Class PatternMatchingMessageHandler
java.lang.Object
dk.cloudcreate.essentials.components.foundation.messaging.eip.store_and_forward.PatternMatchingMessageHandler
Pattern matching Consumer<Message> for use with
The
Inboxes/Inbox or Outboxes/OutboxThe
PatternMatchingMessageHandler 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 provided Consumer)
Each method may also include a 2nd argument that of type Message 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 PatternMatchingMessageHandler {
@MessageHandler
public void handle(OrderEvent.OrderAdded orderAdded) {
...
}
@MessageHandler
private void handle(OrderEvent.ProductRemovedFromOrder productRemovedFromOrder, Message message) {
...
}
}
-
Constructor Summary
ConstructorsConstructorDescriptionCreate anPatternMatchingMessageHandlerthat can resolve and invoke message handler methods, i.e.PatternMatchingMessageHandler(Object invokeMessageHandlerMethodsOn) Create anPatternMatchingMessageHandlerthat can resolve and invoke message handler methods, i.e.PatternMatchingMessageHandler(Object invokeMessageHandlerMethodsOn, List<MessageHandlerInterceptor> interceptors) Create anPatternMatchingMessageHandlerthat can resolve and invoke message handler methods, i.e.PatternMatchingMessageHandler(List<MessageHandlerInterceptor> interceptors) Create anPatternMatchingMessageHandlerthat can resolve and invoke message handler methods, i.e. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddInterceptor(MessageHandlerInterceptor interceptor) voidShould 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 anIllegalArgumentExceptionbooleanhandlesMessageWithPayload(Class<?> payloadType) Check amongst all theMessageHandlerannotated methods and check if there's a method that matches (i.e.protected 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)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(Message)will throw anIllegalArgumentExceptionremoveInterceptor(MessageHandlerInterceptor interceptor) voidsetAllowUnmatchedMessages(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 Details
-
PatternMatchingMessageHandler
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(Object invokeMessageHandlerMethodsOn, List<MessageHandlerInterceptor> interceptors) 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 methodsinterceptors- message handler interceptors
-
PatternMatchingMessageHandler
public PatternMatchingMessageHandler()Create anPatternMatchingMessageHandlerthat can resolve and invoke message handler methods, i.e. methods annotated with @MessageHandler, on this concrete subclass ofPatternMatchingMessageHandler -
PatternMatchingMessageHandler
Create anPatternMatchingMessageHandlerthat can resolve and invoke message handler methods, i.e. methods annotated with @MessageHandler, on this concrete subclass ofPatternMatchingMessageHandler
-
-
Method Details
-
addInterceptor
-
removeInterceptor
-
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:
-
accept
-
handleUnmatchedMessage
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
-
handlesMessageWithPayload
Check amongst all theMessageHandlerannotated methods and check if there's a method that matches (i.e. is type compatible) with thepayloadType.- Parameters:
payloadType- theMessage.getPayload()'s concrete type- Returns:
- true if there's a
MessageHandlerannotated method that accepts aMessagewith aMessage.getPayload()of the givenpayloadType, otherwise false
-