Class PatternMatchingQueuedMessageHandler
- java.lang.Object
-
- dk.cloudcreate.essentials.components.foundation.messaging.queue.PatternMatchingQueuedMessageHandler
-
- All Implemented Interfaces:
QueuedMessageHandler
public class PatternMatchingQueuedMessageHandler extends Object implements QueuedMessageHandler
Pattern matchingQueuedMessageHandlerfor use withDurableQueues's
ThePatternMatchingQueuedMessageHandlerwill automatically call methods annotated with the @MessageHandler annotation and where the 1st argument matches the actual Message payload type (contained in theMessage.getPayload()provided to theQueuedMessageHandler.handle(QueuedMessage)method)Each method may also include a 2nd argument that of type
QueuedMessagein 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:
{@code public class MyMessageHandler extends PatternMatchingQueuedMessageHandler {
-
-
Constructor Summary
Constructors Constructor Description PatternMatchingQueuedMessageHandler()Create 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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidallowUnmatchedMessages()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 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)booleanisAllowUnmatchedMessages()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 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 Detail
-
PatternMatchingQueuedMessageHandler
public PatternMatchingQueuedMessageHandler(Object invokeMessageHandlerMethodsOn)
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 Detail
-
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:
setAllowUnmatchedMessages(boolean)
-
handle
public void handle(QueuedMessage queuedMessage)
- Specified by:
handlein interfaceQueuedMessageHandler
-
handleUnmatchedMessage
protected void handleUnmatchedMessage(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)- Parameters:
queuedMessage- the unmatched queue message
-
-