Class MultiStreamableMessageSource

java.lang.Object
org.axonframework.eventhandling.MultiStreamableMessageSource
All Implemented Interfaces:
StreamableMessageSource<TrackedEventMessage<?>>
Direct Known Subclasses:
MultiStreamableMessageSource

public class MultiStreamableMessageSource extends Object implements StreamableMessageSource<TrackedEventMessage<?>>
Implementation which allows for tracking processors to process messages from an arbitrary number of sources. The order in which messages from each stream are consumed is configurable but defaults to the oldest message available (using the event's timestamp). When the stream is polled for a specified duration, each stream is called with BlockingStream.hasNextAvailable() except for the last stream configured by the MultiStreamableMessageSource.Builder.addMessageSource(String, StreamableMessageSource) or by explicit configuration using MultiStreamableMessageSource.Builder.longPollingSource(String). This stream long polls for a fraction of the specified duration before looping through the sources again repeating until the duration has been met. This ensures the highest chance of a consumable message being found.
Since:
4.2
Author:
Greg Woods
  • Constructor Details

  • Method Details

    • builder

      public static MultiStreamableMessageSource.Builder builder()
      Instantiate a Builder to be able to create an MultiStreamableMessageSource. The configurable field trackedEventComparator, which decides which message to process first if there is a choice defaults to the oldest message available (using the event's timestamp).
      Returns:
      A Builder to be able to create a MultiStreamableMessageSource.
    • openStream

      public org.axonframework.eventhandling.MultiStreamableMessageSource.MultiSourceBlockingStream openStream(TrackingToken trackingToken)
      Opens a stream for each event source at the specified token position.
      Specified by:
      openStream in interface StreamableMessageSource<TrackedEventMessage<?>>
      Parameters:
      trackingToken - Object containing the position in the stream or null to open a stream containing all messages.
      Returns:
      An instance of MultiStreamableMessageSource.MultiSourceBlockingStream with open streams for each event source.
    • createTailToken

      public MultiSourceTrackingToken createTailToken()
      Description copied from interface: StreamableMessageSource
      Creates the token at the beginning of an event stream. The beginning of an event stream in this context means the token of very first event in the stream.

      The default behavior for this method is to return null, which always represents the tail position of a stream. However, implementations are encouraged to return an instance that explicitly represents the tail of the stream.

      Specified by:
      createTailToken in interface StreamableMessageSource<TrackedEventMessage<?>>
      Returns:
      the token at the beginning of an event stream
    • createHeadToken

      public MultiSourceTrackingToken createHeadToken()
      Description copied from interface: StreamableMessageSource
      Creates the token at the end of an event stream. The end of an event stream in this context means the token of very last event in the stream.
      Specified by:
      createHeadToken in interface StreamableMessageSource<TrackedEventMessage<?>>
      Returns:
      the token at the end of an event stream
    • createTokenAt

      public MultiSourceTrackingToken createTokenAt(Instant dateTime)
      Description copied from interface: StreamableMessageSource
      Creates a token that tracks all events after given dateTime. If there is an event exactly at the given dateTime, it will be tracked too.
      Specified by:
      createTokenAt in interface StreamableMessageSource<TrackedEventMessage<?>>
      Parameters:
      dateTime - The date and time for determining criteria how the tracking token should be created. A tracking token should point at very first event before this date and time.
      Returns:
      a tracking token at the given dateTime, if there aren't events matching this criteria null is returned
    • createTokenSince

      public MultiSourceTrackingToken createTokenSince(Duration duration)
      Description copied from interface: StreamableMessageSource
      Creates a token that tracks all events since the last duration. If there is an event exactly at that time (before given duration), it will be tracked too.
      Specified by:
      createTokenSince in interface StreamableMessageSource<TrackedEventMessage<?>>
      Parameters:
      duration - The duration for determining criteria how the tracking token should be created. A tracking token should point at very first event before this duration.
      Returns:
      a tracking token that depicts position before given duration, if there aren't events matching this criteria null is returned