Section | |||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
Overview
This page assumes you have read Working with Messaging to understand the basics of SMA messaging.
Section | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Understanding Message SendMessages are sent over message bus channels in a fire and forget fashion - the application can rely on the underlying AepEngine to deliver the message according the quality of service configured for a channel. An application views message channels as a logical, ordered conduits over which messages flow. The diagram below depicts the path of a message sent through an engine. The basic flow of sending is as follows:
Solicited vs Unsolicited SendsWhen an outbound message is sent from within an application event handler, it is refered to as a solicited send. When an application is sent from outside of a message handler it is refered to as an unsolicited send.
Creating MessagesMessage types generated by the application data modeler can be created via their static create() method. Application code populates message contents as a regular pojo. Message Concurrency and PoolingOutbound messages sent by the application may be serialized in background threads,. So:
An application that would like to send the same message multiple times can use the copy() method on the message. The copy can be modified and used in a subsequent send call. Message may also be pooled by the platform. This is the reason that message construction is done through static create methods. Once the platform has finished sending them, their backing contents can be wiped and the view reused in a subsequent sent. So:
Sending MessagesUsing Aep Message Sender
The simplest way to send a message is to add an AppInjectionPoint annotation that allows the XVM to inject a message sender. The application then supplies the bus and channel name along with the message.
See also: Sending via the AepEngineWhen not using the AepMessageSender an application must provide the MessageChannel in the AepEngine's sendMessage call. When using this pattern the application can register event handlers for channel up and down events which are dispatched to the application when messaging is started or stopped. The application can qualify the EventHandler annotation to identify a particular channelName@busName to specify the channel of interest:
Channel Keys and Dynamic TopicsThe channel key is used to Channel key of Message Reflectors
Key Resolution TablesIn many cases substitution values for a dynamic key would come from the application environment or configuration. Message channels can be configured with a key resolution to allow substitution of key variables that don't come from the message being sent.
Message SequencingHA ConsiderationsOnly the primary instance of an application will establish messaging connections Understanding Message DispatchAn application's Aep Engine creates and manages the lifecycle of the message buses that an application configures for use. When an application is configured to join one of more bus channels subscriptions will be issued on behalf of the application to attract messages. Message dispatch occurs as follows:
Expressing InterestFor an application to receive messages, it must:
Configuring Channels For JoinIn order for the application's AepEninge to issue subscriptions for the message channel on which a message is sent it must be joined. Buses and channels are configured via the platform's configuration DDL. The below configuration snippet demonstrates:
Adding an EventHandlerWhen a message is received by a message bus it is enqueued into the application's Inbound Event Queue to be queued for dispatch, the engine will pick up
The application's underlying AepEngine will ensure that the message is acknowledged once state changes made by the handler have been stabilized. That coupled with the engine's message deduplication features ensures that even in the event of failover, the handler will only be executed once. Channel FiltersA channel filter filters variable parts of a channel key to filter what is received over a message channel and is used to determine the subscriptions issued on behalf of the application. Channel filter take the following form: For example: given a channel key of
If a variable portion of the channel key is omitted in a filter, it will result in the subscription being joined in a wildcard fashion (assuming the underlying bus implementation supports wildcards). So given a channel key of
Finally, if the channel filter is set to null for the channel key in the example above, then the resulting subscription would be:
Registering Message View FactoriesMessage bus binding implementations receive messages in serialized form and wrap them with a MessageView that is passed to the application to work with. MessageViews are wrapped by locating the message |
...
MessageViewFactory for the message which is typically generated |
...
by ADM. To locate the factory and message type a binding consults Message Metadata |
...
that is transported along with the serialized message. An application must therefore register the message factories it intends to use so that bus binding can find the factories. This can be done in 2 ways: Registration via Config DDLMost often, applications will list message view factories that they use in their DDL Config:
ProgrammaticallyRegistration can also be done programmatically via the AepEngine. A common way to do this is to provide an AppInjectionPoint for the AepEngine in the application:
Preserving Subscriptions on ShutdownBy default when an engine is stopped without an error bus channels that were 'joined' will be 'left' meaning that any subscriptions or interests created by the message bus will be unsubscribed or unregistered. This behavior can be overridden by configuring an application to preserve channel joins on stop:
Note that this property has no effect for the case where an engine shuts down with an error (e.g. |
...
with a non null cause. In this case channel joins are left in tact allowing a backup to take over. This behavior can also be overridden programmatically on a case by case basis by an EventHandler for the |
...
setting See Also |
...