Event introduction
Connecting an external system with the enmeshed Connector, the main communication is performed by addressing the Connector’s REST API. This way, processes can be initiated by the organization’s backend service or data can be requested from the Connector. In addition, events offer the possibility for the Connector to actively give feedback to the external system. Thus, a bidirectional communication is established.
What is an event?
Events are predefined datastructures used within enmeshed to communicate a significant change of an entity’s state. They are heavily used internally by the enmeshed Runtime, but can also be propagated by the Connector to external systems. Thus, these systems don’t have to perform long polling, in order to receive changes, but are actively informed once they occur. This is not only more efficient, also, its is safer, since it keeps you updated about all changes of interest. Working with events allows to determine routines, that are executed whenever a specific event arises, called handlers. An overview of the Connector events that may occur is given in the corresponding section.
Motivation for using events
As an exemplary process of how working with events can benefit your mode of operation, we look at the procedure of exchanging Messages
.
Procedure without events
Firstly, we consider the case without using events.
To send a Message
, the external system posts the corresponding request to the REST API of the Connector.
Then, it regularly fetches its state, until a response is received.
This might take many cycles, depending on the refresh rate, and implies a delay between the time the response is received by the Connector and the external system.
Procedure with events
In contrast, if you work with events, as soon as the Connector successfully sent your Message
, a transport.messageSent
event will be transmitted to your system as a confirmation.
Awaiting the response, no long polling is necessary, since the Connector actively sends a transport.messageReceived
event, containing the answer, once it is received.
Modules to receive events
In order to receive events, the Connector needs to be synchronized with the Backbone. This can be automated using the Sync Module. Fetching changes from the Backbone regularly, it forwards the received events to Modules that are configured to process them, e.g. Message Broker Publisher or Webhooks. Working with message brokers has the advantage that events are conserved, even in case of a downtime of the recipient. Thus, we recommend to work with the message broker module instead of Webhooks.