Class PatternMatchingMessageHandler
- java.lang.Object
-
- dk.cloudcreate.essentials.components.foundation.messaging.eip.store_and_forward.PatternMatchingMessageHandler
-
public class PatternMatchingMessageHandler extends Object implements Consumer<Message>
Pattern matching Consumer<Message> for use withInboxes/InboxorOutboxes/Outbox
ThePatternMatchingMessageHandlerwill 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 the providedConsumer)Each method may also include a 2nd argument that of type
Messagein 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 PatternMatchingMessageHandler {
-
-
Constructor Summary
Constructors Constructor Description PatternMatchingMessageHandler()Create anPatternMatchingMessageHandlerthat can resolve and invoke message handler methods, i.e.PatternMatchingMessageHandler(Object invokeMessageHandlerMethodsOn)Create anPatternMatchingMessageHandlerthat can resolve and invoke message handler methods, i.e.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaccept(Message message)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(Message)will throw anIllegalArgumentExceptionprotected voidhandleUnmatchedMessage(Message message)Override this method to provide custom handling forMessage'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(Message)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(Message)will throw anIllegalArgumentException
-
-
-
Constructor Detail
-
PatternMatchingMessageHandler
public PatternMatchingMessageHandler(Object invokeMessageHandlerMethodsOn)
Create anPatternMatchingMessageHandlerthat 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
-
PatternMatchingMessageHandler
public PatternMatchingMessageHandler()
Create anPatternMatchingMessageHandlerthat can resolve and invoke message handler methods, i.e. methods annotated with @MessageHandler, on this concrete subclass ofPatternMatchingMessageHandler
-
-
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(Message)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(Message)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(Message)will throw anIllegalArgumentException- See Also:
setAllowUnmatchedMessages(boolean)
-
handleUnmatchedMessage
protected void handleUnmatchedMessage(Message message)
Override this method to provide custom handling forMessage's who'sMessage.getPayload()aren't matched
Default behaviour is to throw anIllegalArgumentExceptionunlessisAllowUnmatchedMessages()is set to true (default value is false)- Parameters:
message- the unmatched message
-
-