Class MessageDispatcher

java.lang.Object
de.otto.synapse.consumer.MessageDispatcher
All Implemented Interfaces:
java.util.function.Consumer<TextMessage>

public class MessageDispatcher
extends java.lang.Object
implements java.util.function.Consumer<TextMessage>
A MessageConsumer that is acting as a Message Dispatcher for multiple message consumers.

MessageDispatcher

As it is implementing the MessageConsumer interface, the MessageDispatcher is an implementation of the GoF Composite Pattern.

Messages are translated by the dispatcher using to the format expected by the registered consumers.

See Also:
EIP: Message Dispatcher, Composite Pattern
  • Constructor Summary

    Constructors
    Constructor Description
    MessageDispatcher()  
    MessageDispatcher​(java.util.List<MessageConsumer<?>> messageConsumers)  
  • Method Summary

    Modifier and Type Method Description
    void accept​(TextMessage message)
    Accepts a message with JSON String payload, dispatches this method to the different registered consumers if their MessageConsumer.keyPattern() matches, and translates the JSON payload into the expected MessageConsumer.payloadType() of the receiving MessageConsumer.
    void add​(MessageConsumer<?> messageConsumer)  
    java.util.List<MessageConsumer<?>> getAll()  
    java.util.regex.Pattern keyPattern()
    Returns the pattern of event keys accepted by this consumer.
    java.lang.Class<java.lang.String> payloadType()
    Returns the expected payload type of events consumed by this EventConsumer.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface java.util.function.Consumer

    andThen
  • Constructor Details

    • MessageDispatcher

      public MessageDispatcher()
    • MessageDispatcher

      public MessageDispatcher​(java.util.List<MessageConsumer<?>> messageConsumers)
  • Method Details

    • add

      public void add​(MessageConsumer<?> messageConsumer)
    • getAll

      public java.util.List<MessageConsumer<?>> getAll()
    • payloadType

      @Nonnull public java.lang.Class<java.lang.String> payloadType()
      Returns the expected payload type of events consumed by this EventConsumer.
      Returns:
      payload type
    • keyPattern

      @Nonnull public java.util.regex.Pattern keyPattern()
      Returns the pattern of event keys accepted by this consumer.
      Returns:
      Pattern
    • accept

      public void accept​(TextMessage message)
      Accepts a message with JSON String payload, dispatches this method to the different registered consumers if their MessageConsumer.keyPattern() matches, and translates the JSON payload into the expected MessageConsumer.payloadType() of the receiving MessageConsumer.
      Specified by:
      accept in interface java.util.function.Consumer<TextMessage>
      Parameters:
      message - the input argument