Package de.otto.synapse.consumer
Class StatefulMessageConsumer<P,S>
java.lang.Object
de.otto.synapse.consumer.StatefulMessageConsumer<P,S>
- Type Parameters:
P- the type of theMessagepayloadS- the type of theStateRepositoryentries
- All Implemented Interfaces:
MessageConsumer<P>,java.util.function.Consumer<Message<P>>
public class StatefulMessageConsumer<P,S> extends java.lang.Object implements MessageConsumer<P>
A
MessageConsumer that is updating a StateRepository.-
Constructor Summary
Constructors Constructor Description StatefulMessageConsumer(java.lang.String keyPattern, java.lang.Class<P> payloadType, StateRepository<S> stateRepository, java.util.function.BiFunction<java.util.Optional<S>,? super Message<P>,S> payloadToStateMapper, java.util.function.Function<? super Message<P>,java.lang.String> keyMapper)Creates a StatefulMessageConsumer.StatefulMessageConsumer(java.lang.String keyPattern, java.lang.Class<P> payloadType, StateRepository<S> stateRepository, java.util.function.BiFunction<java.util.Optional<S>,Message<P>,S> payloadToStateMapper)Creates a StatefulMessageConsumer.StatefulMessageConsumer(java.lang.String keyPattern, java.lang.Class<P> payloadType, StateRepository<S> stateRepository, java.util.function.Function<? super Message<P>,S> payloadToStateMapper, java.util.function.Function<? super Message<P>,java.lang.String> keyMapper)Creates a StatefulMessageConsumer.StatefulMessageConsumer(java.lang.String keyPattern, java.lang.Class<P> payloadType, StateRepository<S> stateRepository, java.util.function.Function<Message<P>,S> payloadToStateMapper)Creates a StatefulMessageConsumer. -
Method Summary
Modifier and Type Method Description voidaccept(Message<P> message)java.util.regex.PatternkeyPattern()Returns the pattern ofmessage keysaccepted by this consumer.java.lang.Class<P>payloadType()Returns the expected payload type ofeventsconsumed by this EventConsumer.
-
Constructor Details
-
StatefulMessageConsumer
public StatefulMessageConsumer(java.lang.String keyPattern, java.lang.Class<P> payloadType, StateRepository<S> stateRepository, java.util.function.Function<Message<P>,S> payloadToStateMapper)Creates a StatefulMessageConsumer.The message's
Key.partitionKey()is used as the key for repository entries.- Parameters:
keyPattern- the of-pattern ofmessage keysaccepted by this consumer.payloadType- the payload type of the messages accepted by this consumerstateRepository- the StateRepository that is holding the StatepayloadToStateMapper- the mapper function used to map message payload to state entities
-
StatefulMessageConsumer
public StatefulMessageConsumer(java.lang.String keyPattern, java.lang.Class<P> payloadType, StateRepository<S> stateRepository, java.util.function.BiFunction<java.util.Optional<S>,Message<P>,S> payloadToStateMapper)Creates a StatefulMessageConsumer.The message's
Key.partitionKey()is used as the key for repository entries.- Parameters:
keyPattern- the of-pattern ofmessage keysaccepted by this consumer.payloadType- the payload type of the messages accepted by this consumerstateRepository- the StateRepository that is holding the StatepayloadToStateMapper- the mapper function used to map message payload to state entities
-
StatefulMessageConsumer
public StatefulMessageConsumer(java.lang.String keyPattern, java.lang.Class<P> payloadType, StateRepository<S> stateRepository, java.util.function.Function<? super Message<P>,S> payloadToStateMapper, java.util.function.Function<? super Message<P>,java.lang.String> keyMapper)Creates a StatefulMessageConsumer.- Parameters:
keyPattern- the of-pattern ofmessage keysaccepted by this consumer.payloadType- the payload type of the messages accepted by this consumerstateRepository- the StateRepository that is holding the StatepayloadToStateMapper- the mapper function used to map message payload to state entitieskeyMapper- the mapper function used to map message keys to StateRepository keys.
-
StatefulMessageConsumer
public StatefulMessageConsumer(java.lang.String keyPattern, java.lang.Class<P> payloadType, StateRepository<S> stateRepository, java.util.function.BiFunction<java.util.Optional<S>,? super Message<P>,S> payloadToStateMapper, java.util.function.Function<? super Message<P>,java.lang.String> keyMapper)Creates a StatefulMessageConsumer.- Parameters:
keyPattern- the of-pattern ofmessage keysaccepted by this consumer.payloadType- the payload type of the messages accepted by this consumerstateRepository- the StateRepository that is holding the StatepayloadToStateMapper- the mapper function used to map previous state entity and message payload to state entitieskeyMapper- the mapper function used to map message keys to StateRepository keys.
-
-
Method Details
-
payloadType
Returns the expected payload type ofeventsconsumed by this EventConsumer.- Specified by:
payloadTypein interfaceMessageConsumer<P>- Returns:
- payload type
-
keyPattern
@Nonnull public java.util.regex.Pattern keyPattern()Returns the pattern ofmessage keysaccepted by this consumer.- Specified by:
keyPatternin interfaceMessageConsumer<P>- Returns:
- Pattern
-
accept
- Specified by:
acceptin interfacejava.util.function.Consumer<P>
-