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>,Consumer<Message<P>>
A
MessageConsumer that is updating a StateRepository.-
Constructor Summary
ConstructorsConstructorDescriptionStatefulMessageConsumer(String keyPattern, Class<P> payloadType, StateRepository<S> stateRepository, BiFunction<Optional<S>, ? super Message<P>, S> payloadToStateMapper, Function<? super Message<P>, String> keyMapper) Creates a StatefulMessageConsumer.StatefulMessageConsumer(String keyPattern, Class<P> payloadType, StateRepository<S> stateRepository, BiFunction<Optional<S>, Message<P>, S> payloadToStateMapper) Creates a StatefulMessageConsumer.StatefulMessageConsumer(String keyPattern, Class<P> payloadType, StateRepository<S> stateRepository, Function<? super Message<P>, S> payloadToStateMapper, Function<? super Message<P>, String> keyMapper) Creates a StatefulMessageConsumer.StatefulMessageConsumer(String keyPattern, Class<P> payloadType, StateRepository<S> stateRepository, Function<Message<P>, S> payloadToStateMapper) Creates a StatefulMessageConsumer. -
Method Summary
Modifier and TypeMethodDescriptionvoidReturns the pattern ofmessage keysaccepted by this consumer.Returns the expected payload type ofeventsconsumed by this EventConsumer.
-
Constructor Details
-
StatefulMessageConsumer
public StatefulMessageConsumer(String keyPattern, Class<P> payloadType, StateRepository<S> stateRepository, 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(String keyPattern, Class<P> payloadType, StateRepository<S> stateRepository, BiFunction<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(String keyPattern, Class<P> payloadType, StateRepository<S> stateRepository, Function<? super Message<P>, S> payloadToStateMapper, Function<? super Message<P>, 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(String keyPattern, Class<P> payloadType, StateRepository<S> stateRepository, BiFunction<Optional<S>, ? super Message<P>, S> payloadToStateMapper, Function<? super Message<P>, 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
Returns the pattern ofmessage keysaccepted by this consumer.- Specified by:
keyPatternin interfaceMessageConsumer<P>- Returns:
- Pattern
-
accept
-