Package org.axonframework.eventhandling
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
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classBuilder class to instantiate aMultiStreamableMessageSource. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedInstantiate aMultiStreamableMessageSourcebased on the fields contained in theMultiStreamableMessageSource.Builder. -
Method Summary
Modifier and TypeMethodDescriptionbuilder()Instantiate a Builder to be able to create anMultiStreamableMessageSource.Creates the token at the end of an event stream.Creates the token at the beginning of an event stream.createTokenAt(Instant dateTime) Creates a token that tracks all events after givendateTime.createTokenSince(Duration duration) Creates a token that tracks all events since the lastduration.org.axonframework.eventhandling.MultiStreamableMessageSource.MultiSourceBlockingStreamopenStream(TrackingToken trackingToken) Opens a stream for each event source at the specified token position.
-
Constructor Details
-
MultiStreamableMessageSource
Instantiate aMultiStreamableMessageSourcebased on the fields contained in theMultiStreamableMessageSource.Builder.- Parameters:
builder- TheMultiStreamableMessageSource.Builderused to instantiate aMultiStreamableMessageSourceinstance.
-
-
Method Details
-
builder
Instantiate a Builder to be able to create anMultiStreamableMessageSource. The configurable fieldtrackedEventComparator, 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:
openStreamin interfaceStreamableMessageSource<TrackedEventMessage<?>>- Parameters:
trackingToken- Object containing the position in the stream ornullto open a stream containing all messages.- Returns:
- An instance of
MultiStreamableMessageSource.MultiSourceBlockingStreamwith open streams for each event source.
-
createTailToken
Description copied from interface:StreamableMessageSourceCreates 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:
createTailTokenin interfaceStreamableMessageSource<TrackedEventMessage<?>>- Returns:
- the token at the beginning of an event stream
-
createHeadToken
Description copied from interface:StreamableMessageSourceCreates 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:
createHeadTokenin interfaceStreamableMessageSource<TrackedEventMessage<?>>- Returns:
- the token at the end of an event stream
-
createTokenAt
Description copied from interface:StreamableMessageSourceCreates a token that tracks all events after givendateTime. If there is an event exactly at the givendateTime, it will be tracked too.- Specified by:
createTokenAtin interfaceStreamableMessageSource<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 criterianullis returned
-
createTokenSince
Description copied from interface:StreamableMessageSourceCreates a token that tracks all events since the lastduration. If there is an event exactly at that time (before givenduration), it will be tracked too.- Specified by:
createTokenSincein interfaceStreamableMessageSource<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 criterianullis returned
-