...
Before diving into the details of send and receive, it is helpful to understand how message buses are configured for an application. Message buses are resources that are shared between applications. In configuration message buses are defined independently of applications to provide the common connection details and the set of channels that they provide for applications. Applications will reference the buses that they will use to collaborate with other applications along with a subset of the channels that they will work with. Applications work abstractly with buses and channel to send and receive messages, allowing configuration changes at runtime to augment:
- The messaging provider (for example to switch from ActiveMQ to Solace)
- The message bus connection details in the form of an address and optionally a port (for example to switch from a message broker in a test environment to one in production).
- Bus connection properties, a combination of properties that are common to all bus providers and configuration specific to the type of bus provider being used.
- Topic structure by modifying the channels' configured keys.
- Application subscriptions by modifying the applications' configured filters.
...
- The application creates a message.
- The application calls send, passing the message and channel name.
- The engine looks up the channel and uses it to resolves the physical destination on which the message will be sent via the configured channel key.
- The engine queues the message for send until the associated state changes for the message handler are stabilized to the application's store (e.g replication and transaction log write).
- When the transaction is committed the message is serialized to its backing buffer, packaged in a message bus provider specific message along with message metadata containing the message type information used by receivers to deserialize the message.
...
Code Block | ||||
---|---|---|---|---|
| ||||
public class MyApp { private volatile MessageChannel orderEventChannel; private volatile AepEngine aepEngine; @AppInjectionPoint public void onEngineInjected(AepEngine aepEngine) { this.aepEngine = aepEngine; } @EventHandler(source = "order-event-channel@order-processing-bus") public void onOrderEventChannelUp(AepChannelUpEvent channelUpEvent) { this.orderEventChannel= channelUpEvent.getChannel(); } @EventHandler(source = "new-orders-channel@order-processing-bus") public void onOnOrderEventChannelDownonOrderEventChannelDown(AepChannelDownEvent channelDownEvent) { this.orderEventChannel= null; } @EventHandler public void onNewOrder(NewOrderMessage message) { OrderEventMessage event = OrderEventMessage.create(); event.setOrderId(message.getOrderId()); // The channel name and bus must be set on the message // if using Event Sourcing because handlers are invoked // on the backup and during recovery before messaging is // started. // // This is not required when using State Replication. event.setMessageChannel("order-event-channel"); event.setMessageBus("order-processing-bus"); aepEngine.sendMessage(orderEventChannel, event); } } |
...