Class PatternMatchingQueuedMessageHandler
java.lang.Object
dk.cloudcreate.essentials.components.foundation.messaging.queue.PatternMatchingQueuedMessageHandler
- All Implemented Interfaces:
QueuedMessageHandler
Pattern matching
The
QueuedMessageHandler for use with DurableQueues'sThe
PatternMatchingQueuedMessageHandler will automatically call methods annotated with the @MessageHandler annotation and
where the 1st argument matches the actual Message payload type (contained in the Message.getPayload() provided to the QueuedMessageHandler.handle(QueuedMessage) method)
Each method may also include a 2nd argument that of type QueuedMessage in which case the event that's being matched is included as the 2nd argument in the call to the method.
The methods can have any accessibility (private, public, etc.), they just have to be instance methods.
Example:
public class MyMessageHandler extends PatternMatchingQueuedMessageHandler {
@MessageHandler
public void handle(OrderEvent.OrderAdded orderAdded) {
...
}
@MessageHandler
private void handle(OrderEvent.ProductRemovedFromOrder productRemovedFromOrder, QueuedMessage queuedMessage) {
...
}
}
-
Constructor Summary
ConstructorsConstructorDescriptionCreate anPatternMatchingQueuedMessageHandlerthat can resolve and invoke message handler methods, i.e.PatternMatchingQueuedMessageHandler(Object invokeMessageHandlerMethodsOn) Create anPatternMatchingQueuedMessageHandlerthat can resolve and invoke message handler methods, i.e. -
Method Summary
Modifier and TypeMethodDescriptionvoidShould the event handler allow unmatchedMessage.getPayload()? If true then an unmatchedMessage.getPayload()is ignored, if false (the default value) then an unmatched event will causehandleUnmatchedMessage(QueuedMessage)will throw anIllegalArgumentExceptionvoidhandle(QueuedMessage queuedMessage) protected voidhandleUnmatchedMessage(QueuedMessage queuedMessage) Override this method to provide custom handling forQueuedMessage's who'sMessage.getPayload()aren't matched
Default behaviour is to throw anIllegalArgumentExceptionunlessisAllowUnmatchedMessages()is set to true (default value is false)booleanShould the event handler allow unmatchedMessage.getPayload()? If true then an unmatchedMessage.getPayload()is ignored, if false (the default value) then an unmatched event will causehandleUnmatchedMessage(QueuedMessage)will throw anIllegalArgumentExceptionvoidsetAllowUnmatchedMessages(boolean allowUnmatchedMessages) Should the event handler allow unmatchedMessage.getPayload()? If true then an unmatchedMessage.getPayload()is ignored, if false (the default value) then an unmatched event will causehandleUnmatchedMessage(QueuedMessage)will throw anIllegalArgumentException
-
Constructor Details
-
PatternMatchingQueuedMessageHandler
Create anPatternMatchingQueuedMessageHandlerthat can resolve and invoke message handler methods, i.e. methods annotated with @MessageHandler, on another object- Parameters:
invokeMessageHandlerMethodsOn- the object that contains the @MessageHandler annotated methods
-
PatternMatchingQueuedMessageHandler
public PatternMatchingQueuedMessageHandler()Create anPatternMatchingQueuedMessageHandlerthat can resolve and invoke message handler methods, i.e. methods annotated with @MessageHandler, on this concrete subclass ofPatternMatchingQueuedMessageHandler
-
-
Method Details
-
isAllowUnmatchedMessages
public boolean isAllowUnmatchedMessages()Should the event handler allow unmatchedMessage.getPayload()? If true then an unmatchedMessage.getPayload()is ignored, if false (the default value) then an unmatched event will causehandleUnmatchedMessage(QueuedMessage)will throw anIllegalArgumentException- Returns:
- should the event handler allow unmatched events
-
setAllowUnmatchedMessages
public void setAllowUnmatchedMessages(boolean allowUnmatchedMessages) Should the event handler allow unmatchedMessage.getPayload()? If true then an unmatchedMessage.getPayload()is ignored, if false (the default value) then an unmatched event will causehandleUnmatchedMessage(QueuedMessage)will throw anIllegalArgumentException- Parameters:
allowUnmatchedMessages- should the event handler allow unmatchedMessage.getPayload()
-
allowUnmatchedMessages
public void allowUnmatchedMessages()Should the event handler allow unmatchedMessage.getPayload()? If true then an unmatchedMessage.getPayload()is ignored, if false (the default value) then an unmatched event will causehandleUnmatchedMessage(QueuedMessage)will throw anIllegalArgumentException- See Also:
-
handle
- Specified by:
handlein interfaceQueuedMessageHandler
-
handleUnmatchedMessage
Override this method to provide custom handling forQueuedMessage's who'sMessage.getPayload()aren't matched
Default behaviour is to throw anIllegalArgumentExceptionunlessisAllowUnmatchedMessages()is set to true (default value is false)- Parameters:
queuedMessage- the unmatched queue message
-