Integration Broker
Dispatches external messages from and to a Bounded Context with which this broker is associated.
In a multi-component environment messages may travel across components from one Bounded Context to another. Accordingly, an IntegrationBroker
is available as a part of a Bounded Context.
An IntegrationBroker
is always based upon transport that delivers messages from and to it. For several Bounded Contexts to communicate, their brokers have to share the transport. Typically, that would be a single message queue.
IntegrationBroker
s communicate with each other in order to keep the whole list of requested messages (needs) and their potential sources (Bounded Contexts) up-to-date. They use two special messages for this:
- ExternalMessagesSourceAvailable is sent when a broker is registered withing a Bounded Context;
- RequestForExternalMessages is sent
- in response to ExternalMessagesSourceAvailable sent by other brokers;
- when internal needs for external messages are changed.
Receiving
The messages from external components received by an IntegrationBroker
via the transport are propagated into the Bounded Context via the domestic EventBus
.
Publishing
The messages requested by other parties are published from the domestic EventBus
with the help of special dispatcher.
Sample Usage
Bounded Context "Projects" has a projection with an event handler that is subscribed to an external event as follows:
public class ProjectListView extends Projection<...> {
{@}Subscribe
public void on(@External UserDeleted event) {
// Remove the projects that belong to this user.
// ...
}
}
Upon a registration of the corresponding repository for this projection in the context, the broker associated with that context is informed that one more external event is needed. It sends out an updated RequestForExternalMessages
saying that UserDeleted
events are needed too.
Let's say the second Context is "Users". Its broker will receive the RequestForExternalMessages
sent by "Projects". To handle it, it will create a bridge between "Users"'s Event Bus (which may eventually be transmitting a UserDeleted
event) and the transport.
Once UserDeleted
is emitted locally in "Users" context, it will be received by this bridge (as well as other local dispatchers) and published to the external transport by its IntegrationBroker
.
The integration broker on the "Projects" side will receive the UserDeleted
external message. The event will be dispatched to the external event handler of the projection.
Limitations
An event type may be consumed by many Contexts but produced only by a single Context. This means that each given event type belongs only to one Context. The ownership of an event type may be changed between the versions of a system, but may not be changed while events are travelling between the Contexts.
Functions
external
messages.external
messages.