Skip to main content

Adapter

Adapters are components within the framework that take care of integration with external systems. Their goal is to expose these systems as a high-level API that is compatible with the framework's naming conventions and also independent of the API or protocol used by the external system.

See the adapter design pattern.

There are two types of adapters supported:

Stream based

Stream based adapters usually communicate with the external system by implementing a protocol that operates directly on top of TCP. They serialize and deserialize a stream of bytes. This happens in two handlers:

  • encode: JavaScript objects passed to these handlers are converted to Buffer, which is then passed to the network.
  • decode: data frames coming from the network are passed to this handler and it converts them to JavaScript objects.

This set of handlers is also known as a codec. Codecs usually also take care of matching responses to their corresponding requests, as these protocols often allow multiplexing.

API based

API based adapters operate with higher level protocols like HTTP or even SDKs that are available for the external system. In this case the codec is not needed, as the API or SDK allows JavaScript objects to be used directly. HTTP is somewhere between the API based and stream based, as the transport part of the communication is solved by the protocol (i.e. request/response matching and boundaries). There is still some need for serialization and deserialization of the request or response body.

Adapter loop

The adapters perform a sequence of steps, where they call handlers with specific names as per the following diagram:

adapter-loopadapter-loop

When a handler with the corresponding name exists in the adapter, it can transform the data being processed. Multiple handlers with the same name can be stacked on top of each other, so that they address different aspects of the communication, for example message level encryption and decryption can be implemented on top of the existing protocol.