Class StatefulMessageConsumer<P,S>

java.lang.Object
de.otto.synapse.consumer.StatefulMessageConsumer<P,S>
Type Parameters:
P - the type of the Message payload
S - the type of the StateRepository entries
All Implemented Interfaces:
MessageConsumer<P>, Consumer<Message<P>>

public class StatefulMessageConsumer<P,S> extends Object implements MessageConsumer<P>
A MessageConsumer that is updating a StateRepository.
  • 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 of message keys accepted by this consumer.
      payloadType - the payload type of the messages accepted by this consumer
      stateRepository - the StateRepository that is holding the State
      payloadToStateMapper - 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 of message keys accepted by this consumer.
      payloadType - the payload type of the messages accepted by this consumer
      stateRepository - the StateRepository that is holding the State
      payloadToStateMapper - 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 of message keys accepted by this consumer.
      payloadType - the payload type of the messages accepted by this consumer
      stateRepository - the StateRepository that is holding the State
      payloadToStateMapper - the mapper function used to map message payload to state entities
      keyMapper - 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 of message keys accepted by this consumer.
      payloadType - the payload type of the messages accepted by this consumer
      stateRepository - the StateRepository that is holding the State
      payloadToStateMapper - the mapper function used to map previous state entity and message payload to state entities
      keyMapper - the mapper function used to map message keys to StateRepository keys.
  • Method Details