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>, 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
    void accept​(Message<P> message)  
    java.util.regex.Pattern keyPattern()
    Returns the pattern of message keys accepted by this consumer.
    java.lang.Class<P> 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

    • 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 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​(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 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​(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 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​(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 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

    • payloadType

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

      @Nonnull public java.util.regex.Pattern keyPattern()
      Returns the pattern of message keys accepted by this consumer.
      Specified by:
      keyPattern in interface MessageConsumer<P>
      Returns:
      Pattern
    • accept

      public void accept​(Message<P> message)
      Specified by:
      accept in interface java.util.function.Consumer<P>