public class MessageDispatcher extends java.lang.Object implements java.util.function.Consumer<TextMessage>
message consumers.
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.
| Constructor and Description |
|---|
MessageDispatcher() |
MessageDispatcher(java.util.List<MessageConsumer<?>> messageConsumers) |
| Modifier and Type | Method and 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. |
public MessageDispatcher()
public MessageDispatcher(java.util.List<MessageConsumer<?>> messageConsumers)
public void add(MessageConsumer<?> messageConsumer)
public java.util.List<MessageConsumer<?>> getAll()
@Nonnull public java.lang.Class<java.lang.String> payloadType()
events consumed by this EventConsumer.@Nonnull public java.util.regex.Pattern keyPattern()
event keys accepted by this consumer.public void accept(TextMessage message)
consumers if their MessageConsumer.keyPattern() matches, and
translates the JSON payload into the expected MessageConsumer.payloadType() of the receiving
MessageConsumer.accept in interface java.util.function.Consumer<TextMessage>message - the input argument