Filtering Messages
In situations where it is challenging or not possible to filter messages on the message bus itself using SMA's message routing and filtering features, a microservice can register a message filter class programmatically. The AEP engine triggers any registered message filter before dispatching messages to the microservice. Although programmatic message filtering is less efficient than bus-level filtering, it can significantly enhance performance by preventing filtered messages from entering the microservice engine's transaction stream and allowing them to be acknowledged upstream more quickly.
Setting Message Filters
Use the setMessageFilter() method on an AepEngine to register a message filter. Message filters apply only to live messages while in the primary role. Filtered messages are acknowledged but not replicated nor logged to the transaction logs.
Effects of a Message Filter
Filtered messages:
Are acknowledged.
Are not logged to the transaction log, inbound message log or replicated to cluster peers.
Are not dispatched to application EventHandlers.
Do not start new transactions or contribute to adaptive batching counts.
Contribute to event received/processed and message received stats, but are accounted for in numMsgsFiltered. They do not undergo duplicate checking so filtered duplicates will not be accounted for duplicate counts.
Message Filter Threading
The message filter is invoked from the same thread as application message handlers. Consequently they need not be coded in a thread safe fashion unless the application sets the same message filter instance on multiple AepEngines.
Exceptions thrown from a Message Filter
If an exception is thrown by a MessageFilter, it is handled according to the AepEngine.AppExceptionHandlingPolicy for this engine. If the policy is AepEngine.AppExceptionHandlingPolicy.LogExceptionAndContinue, the message is not dispatched to application handlers and is acknowledged.
HA Considerations
Any processing done in a message filter is done outside of a transaction and the effects of processing done in a message filter are not replicated to a backup. It is not legal for a message filter to modify the application's recoverable state or to use any of the engine's messaging facilities. Applications using Event Sourcing should take particular care in this regard as it could lead to divergence between a primary and its backup(s).
Last updated

