Interface EventChannel
-
- All Known Implementing Classes:
EventChannelImpl
public interface EventChannelCommunication channel for Event related interactions with AxonServer.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default CompletableFuture<ConfirmationWithConsistencyMarker>appendEvents(Event... events)Append the giveneventsto the Event Store.CompletableFuture<Confirmation>appendSnapshot(Event snapshotEvent)Store the givensnapshotEvent.CompletableFuture<InstructionAck>cancelSchedule(String scheduleToken)Cancels the scheduled publication of an event for which the givenscheduleTokenwas returned.CompletableFuture<CreateResult>createPersistentStream(String streamId, PersistentStreamProperties creationProperties)Opens the persistent stream identified bystreamId.CompletableFuture<Void>deletePersistentStream(String streamId)Deletes a persistent stream.CompletableFuture<Long>findHighestSequence(String aggregateId)Find the highest sequence number (i.e. the sequence number of the most recent event) for an aggregate with givenaggregateId.CompletableFuture<Long>getFirstToken()Retrieves the Token referring to the first Event in the Event Store.CompletableFuture<Long>getLastToken()Retrieves the Token referring to the most recent Event in the Event Store.CompletableFuture<Long>getTokenAt(long instant)Retrieves the token referencing the first Event in the Event Store closest to the giveninstant.default AggregateEventStreamloadSnapshot(String aggregateIdentifier)Loads the Snapshot Event for the givenaggregateIdentifierwith the highest sequence number.default AggregateEventStreamloadSnapshots(String aggregateIdentifier, long maxSequence, int maxResults)Loads Snapshot Events for the givenaggregateIdentifierwith sequence number lower or equal tomaxSequence, returning at mostmaxResultsnumber of snapshots.AggregateEventStreamloadSnapshots(String aggregateIdentifier, long initialSequence, long maxSequence, int maxResults)Loads Snapshot Events for the givenaggregateIdentifierwith sequence number betweeninitialSequenceandmaxSequence(inclusive), returning at mostmaxResultsnumber of snapshots.default AggregateEventStreamopenAggregateStream(String aggregateIdentifier)Opens a stream for consuming Events from a single aggregate, allowing the first event to be a Snapshot Event.AggregateEventStreamopenAggregateStream(String aggregateIdentifier, boolean allowSnapshots)Opens a stream for consuming Events from a single aggregate, with givenallowSnapshotsindicating whether the first Event may be a Snapshot Event.default AggregateEventStreamopenAggregateStream(String aggregateIdentifier, long initialSequence)Opens a stream for consuming Events from a single aggregate, starting with the giveninitialSequence.AggregateEventStreamopenAggregateStream(String aggregateIdentifier, long initialSequence, long maxSequence)Opens a stream for consuming Events from a single aggregate, starting with the giveninitialSequenceuntil the givenmaxSequence.PersistentStreamopenPersistentStream(String streamId, int bufferSize, int refillBatch, PersistentStreamCallbacks callbacks)Opens the persistent stream identified bystreamId.PersistentStreamopenPersistentStream(String streamId, int bufferSize, int refillBatch, PersistentStreamCallbacks callbacks, PersistentStreamProperties creationProperties)Opens the persistent stream identified bystreamId.default EventStreamopenStream(long token, int bufferSize)Opens an EventStream, for sequentially consuming events from AxonServer, starting at giventokenand keeping a local buffer ofbufferSize.default EventStreamopenStream(long token, int bufferSize, int refillBatch)Open an EventStream, for sequentially consuming events from AxonServer, starting at giventokenand keeping a local buffer ofbufferSize, which is refilled after consumingrefillBatchitems.EventStreamopenStream(long token, int bufferSize, int refillBatch, boolean forceReadFromLeader)Open an EventStream, for sequentially consuming events from AxonServer, starting at giventokenand keeping a local buffer ofbufferSize, which is refilled after consumingrefillBatchitems.CompletableFuture<List<StreamStatus>>persistentStreams()Returns a list of persistent streams with the last confirmed token per segment.default ResultStream<EventQueryResultEntry>queryEvents(String queryExpression, boolean liveStream)Queries the Event Store for events using givenqueryExpression.default ResultStream<EventQueryResultEntry>queryEvents(String queryExpression, boolean liveStream, String contextName)Queries the Event Store for events using givenqueryExpression.default ResultStream<EventQueryResultEntry>querySnapshotEvents(String queryExpression, boolean liveStream)Queries the Event Store for snapshot events using givenqueryExpression.default ResultStream<EventQueryResultEntry>querySnapshotEvents(String queryExpression, boolean liveStream, String contextName)Queries the Event Store for snapshot events using givenqueryExpression.default CompletableFuture<String>reschedule(String scheduleToken, Duration triggerDuration, Event event)Convenience method to cancel the scheduled event with givenscheduleTokenand reschedule the giveneventto be published after giventriggerDuration.CompletableFuture<String>reschedule(String scheduleToken, Instant scheduleTime, Event event)Convenience method to cancel the scheduled event with givenscheduleTokenand reschedule the giveneventto be published at givenscheduleTime.CompletableFuture<Void>resetPersistentStreamAtHead(String streamId)Resets the position of a persistent stream to the head (most recent) event in the event store.CompletableFuture<Void>resetPersistentStreamAtPosition(String streamId, long position)Resets the position of a persistent stream to the event at given position (global index) in the event store.CompletableFuture<Void>resetPersistentStreamAtTail(String streamId)Resets the position of a persistent stream to the first (oldest) event in the event store.CompletableFuture<Void>resetPersistentStreamAtTime(String streamId, long instant)Resets the position of a persistent stream to the event at or after the given timestamp in the event store.default CompletableFuture<String>scheduleEvent(Duration triggerDuration, Event event)Schedule the giveneventto be published after giventriggerDuration.CompletableFuture<String>scheduleEvent(Instant scheduleTime, Event event)Schedule the giveneventto be published at givenscheduleTime.CompletableFuture<Void>setPersistentStreamSegments(String streamId, int segments)Updates the number of segments for a persistent stream.AppendEventsTransactionstartAppendEventsTransaction()Starts a new transaction to append events.CompletableFuture<Void>updatePersistentStreamName(String streamId, String streamName)Updates the name for a persistent stream.
-
-
-
Method Detail
-
startAppendEventsTransaction
AppendEventsTransaction startAppendEventsTransaction()
Starts a new transaction to append events.- Returns:
- The transaction reference onto which to register events to append
-
scheduleEvent
default CompletableFuture<String> scheduleEvent(Duration triggerDuration, Event event)
Schedule the giveneventto be published after giventriggerDuration. The returned value can be used to cancel the schedule, or to reschedule the event to another time.- Parameters:
triggerDuration- the amount of time to wait to publish the eventevent- the event to publish- Returns:
- a token used to cancel the schedule
-
scheduleEvent
CompletableFuture<String> scheduleEvent(Instant scheduleTime, Event event)
Schedule the giveneventto be published at givenscheduleTime. The returned value can be used to cancel the schedule, or to reschedule the event to another time.- Parameters:
scheduleTime- The scheduleTime at which to publish the eventevent- The event to publish- Returns:
- a token used to cancel the schedule
-
cancelSchedule
CompletableFuture<InstructionAck> cancelSchedule(String scheduleToken)
Cancels the scheduled publication of an event for which the givenscheduleTokenwas returned.- Parameters:
scheduleToken- the token provided when scheduling the event to be cancelled- Returns:
- a future reference to the result of the instruction
-
reschedule
default CompletableFuture<String> reschedule(String scheduleToken, Duration triggerDuration, Event event)
Convenience method to cancel the scheduled event with givenscheduleTokenand reschedule the giveneventto be published after giventriggerDuration. Is effectively the same as cancelling and scheduling in separate calls, but this call requires only a single round-trip to the server.- Parameters:
scheduleToken- the token of the event to canceltriggerDuration- the point amount of time to wait to publish the eventevent- the event to publish- Returns:
- a future reference to the token for the new schedule
-
reschedule
CompletableFuture<String> reschedule(String scheduleToken, Instant scheduleTime, Event event)
Convenience method to cancel the scheduled event with givenscheduleTokenand reschedule the giveneventto be published at givenscheduleTime. Is effectively the same as cancelling and scheduling in separate calls, but this call requires only a single round-trip to the server.- Parameters:
scheduleToken- the token of the event to cancelscheduleTime- the point in time to publish the new eventevent- the event to publish- Returns:
- a future reference to the token for the new schedule
-
appendEvents
default CompletableFuture<ConfirmationWithConsistencyMarker> appendEvents(Event... events)
Append the giveneventsto the Event Store. Prior to starting, thestartAppendEventsTransaction()method should be invoked- Parameters:
events- theEvents to append to the Event Store- Returns:
- a
CompletableFutureresolving the confirmation of the successful processing of the append transaction
-
findHighestSequence
CompletableFuture<Long> findHighestSequence(String aggregateId)
Find the highest sequence number (i.e. the sequence number of the most recent event) for an aggregate with givenaggregateId.If no events for an aggregate with given identifier have been found, the returned CompletableFuture will resolve to a
nullvalue.- Parameters:
aggregateId- the identifier of the aggregate to find the sequence number for- Returns:
- a CompletableFuture providing the sequence number found, or resolving to
nullwhen no event was found.
-
openStream
default EventStream openStream(long token, int bufferSize)
Opens an EventStream, for sequentially consuming events from AxonServer, starting at giventokenand keeping a local buffer ofbufferSize. When consuming 1/8th of the buffer size (with a minimum of 16), the client will request additional messages to keep the buffer filled.A value for
bufferSizesmaller than 64 items will result in a buffer of 64.The stream of Events starts immediately upon the invocation of this method, making the first messages available for consumption as soon as they have arrived from AxonServer.
- Parameters:
token- the token representing the position to start the stream, or-1to start from beginningbufferSize- the number of events to buffer locally- Returns:
- the Stream for consuming the requested Events
- See Also:
to configure the refill frequency.
-
openStream
default EventStream openStream(long token, int bufferSize, int refillBatch)
Open an EventStream, for sequentially consuming events from AxonServer, starting at giventokenand keeping a local buffer ofbufferSize, which is refilled after consumingrefillBatchitems.A value for
bufferSizesmaller than 64 items will result in a buffer of 64. A value forrefillBatchsmaller than 16 will result in a refill batch of 16. A value larger than thebufferSizewill be reduced to match the givenbufferSize. While this will work, it is not recommended. TherefillBatchshould be sufficiently small to allow for a constant flow of messages to consume.The stream of Events starts immediately upon the invocation of this method, making the first messages available for consumption as soon as they have arrived from AxonServer.
- Parameters:
token- the token representing the position to start the stream, or-1to start from beginningbufferSize- the number of events to buffer locallyrefillBatch- the number of events to be consumed prior to refilling the buffer- Returns:
- the Stream for consuming the requested Events
- See Also:
to use a sensible default for refill batch value.
-
openStream
EventStream openStream(long token, int bufferSize, int refillBatch, boolean forceReadFromLeader)
Open an EventStream, for sequentially consuming events from AxonServer, starting at giventokenand keeping a local buffer ofbufferSize, which is refilled after consumingrefillBatchitems. TheforceReadFromLeaderparameter can be used to enforce this stream to read events from the RAFT leader.A value for
bufferSizesmaller than 64 items will result in a buffer of 64. A value forrefillBatchsmaller than 16 will result in a refill batch of 16. A value larger than thebufferSizewill be reduced to match the givenbufferSize. While this will work, it is not recommended. TherefillBatchshould be sufficiently small to allow for a constant flow of messages to consume.The stream of Events starts immediately upon the invocation of this method, making the first messages available for consumption as soon as they have arrived from AxonServer.
- Parameters:
token- the token representing the position to start the stream, or-1to start from beginningbufferSize- the number of events to buffer locallyrefillBatch- the number of events to be consumed prior to refilling the bufferforceReadFromLeader- abooleandefining whether Events must be read from the leader- Returns:
- the Stream for consuming the requested Events
- See Also:
to use a sensible default for refill batch value.
-
openAggregateStream
default AggregateEventStream openAggregateStream(String aggregateIdentifier)
Opens a stream for consuming Events from a single aggregate, allowing the first event to be a Snapshot Event.Note that this method does not have any form of flow control. All messages are buffered locally. When expecting large streams of events, consider using
openAggregateStream(String, long, long)to retrieve chunks of the event stream instead.- Parameters:
aggregateIdentifier- the identifier of the Aggregate to load events for- Returns:
- a stream of Events for the given Aggregate, for which the first event can be a Snapshot Event
-
openAggregateStream
AggregateEventStream openAggregateStream(String aggregateIdentifier, boolean allowSnapshots)
Opens a stream for consuming Events from a single aggregate, with givenallowSnapshotsindicating whether the first Event may be a Snapshot Event. When givenallowSnapshotsisfalse, this method will return events starting at the first available sequence number of the aggregate (typically 0).Note that this method does not have any form of flow control. All messages are buffered locally. When expecting large streams of events, consider using
openAggregateStream(String, long, long)to retrieve chunks of the event stream instead.- Parameters:
aggregateIdentifier- the identifier of the Aggregate to load events forallowSnapshots- abooleanwhether to allow a snapshot event as first event, or not- Returns:
- a stream of Events for the given Aggregate
-
openAggregateStream
default AggregateEventStream openAggregateStream(String aggregateIdentifier, long initialSequence)
Opens a stream for consuming Events from a single aggregate, starting with the giveninitialSequence. This method will not return a Snapshot Event as first event.Note that this method does not have any form of flow control. All messages are buffered locally. When expecting large streams of events, consider using
openAggregateStream(String, long, long)to retrieve chunks of the event stream instead.- Parameters:
aggregateIdentifier- the identifier of the Aggregate to load events forinitialSequence- the sequence number of the first event to return- Returns:
- a stream of Events for the given Aggregate
-
openAggregateStream
AggregateEventStream openAggregateStream(String aggregateIdentifier, long initialSequence, long maxSequence)
Opens a stream for consuming Events from a single aggregate, starting with the giveninitialSequenceuntil the givenmaxSequence. This method will not return a Snapshot Event as first event.Note: a
maxSequenceof0will result in all events after the initial sequence to be returned.- Parameters:
aggregateIdentifier- the identifier of the Aggregate to load events forinitialSequence- the sequence number of the first event to returnmaxSequence- the sequence number of the last event to return- Returns:
- a stream of Events for the given Aggregate
-
appendSnapshot
CompletableFuture<Confirmation> appendSnapshot(Event snapshotEvent)
Store the givensnapshotEvent.- Parameters:
snapshotEvent- the Snapshot Event to store- Returns:
- a CompletableFuture providing the confirmation upon storage of the snapshot
-
loadSnapshot
default AggregateEventStream loadSnapshot(String aggregateIdentifier)
Loads the Snapshot Event for the givenaggregateIdentifierwith the highest sequence number.Note that the returned stream may not yield any result when there are no snapshots available.
- Parameters:
aggregateIdentifier- the identifier of the Aggregate to retrieve snapshots for- Returns:
- a stream containing the most recent Snapshot Event
-
loadSnapshots
default AggregateEventStream loadSnapshots(String aggregateIdentifier, long maxSequence, int maxResults)
Loads Snapshot Events for the givenaggregateIdentifierwith sequence number lower or equal tomaxSequence, returning at mostmaxResultsnumber of snapshots.Note that Snapshot Events are returned in reverse order of their sequence number.
- Parameters:
aggregateIdentifier- the identifier of the Aggregate to retrieve snapshots formaxSequence- the highest sequence number of snapshots to returnmaxResults- the maximum allowed number of snapshots to return- Returns:
- a stream containing Snapshot Events within the requested bounds
-
loadSnapshots
AggregateEventStream loadSnapshots(String aggregateIdentifier, long initialSequence, long maxSequence, int maxResults)
Loads Snapshot Events for the givenaggregateIdentifierwith sequence number betweeninitialSequenceandmaxSequence(inclusive), returning at mostmaxResultsnumber of snapshots.Note that Snapshot Events are returned in reverse order of their sequence number.
- Parameters:
aggregateIdentifier- the identifier of the Aggregate to retrieve snapshots forinitialSequence- the lowest sequence number of snapshots to returnmaxSequence- the highest sequence number of snapshots to returnmaxResults- the maximum allowed number of snapshots to return- Returns:
- a stream containing Snapshot Events within the requested bounds
-
getLastToken
CompletableFuture<Long> getLastToken()
Retrieves the Token referring to the most recent Event in the Event Store. Using this token to open a stream will only yield events that were appended after execution of this call.- Returns:
- a completable future resolving the Token of the last (i.e. most recent) event
-
getFirstToken
CompletableFuture<Long> getFirstToken()
Retrieves the Token referring to the first Event in the Event Store. Using this token to open a stream will yield all events that available in the event store.- Returns:
- a completable future resolving the Token of the first (i.e. oldest) event
-
getTokenAt
CompletableFuture<Long> getTokenAt(long instant)
Retrieves the token referencing the first Event in the Event Store closest to the giveninstant.The timestamp of the referenced Event may be on or after the given
instantwhen theinstantoccurred within the Event Store's lifecycle. Will return the most recent token when theinstantis placed into the future. Will return the earliest token if theinstantis placed in the past (read: before the existence of this Event Store).Using this token to open a stream will yield all events with a timestamp starting at that instance but may also yield events created before this
instant, whose append transaction completed after theinstant.- Parameters:
instant- The point in time for which to retrieve a token referencing an event within the Event Store. If the giveninstantresides outside the Event Store its existing time frame, the latest or earliest token is returned for a future or pastinstantrespectively.- Returns:
- A completable future resolving the Token of the first (i.e. oldest) event with timestamp on or after
given
instant.
-
queryEvents
default ResultStream<EventQueryResultEntry> queryEvents(String queryExpression, boolean liveStream)
Queries the Event Store for events using givenqueryExpression. The givenliveStreamindicates whether the query should complete when the end of the Event Stream is reached, or if the query should continue processing events as they are stored.- Parameters:
queryExpression- a valid Event Stream Query Language expressionliveStream- whether to continue processing live events- Returns:
- a ResultStream containing the query results
-
queryEvents
default ResultStream<EventQueryResultEntry> queryEvents(String queryExpression, boolean liveStream, String contextName)
Queries the Event Store for events using givenqueryExpression. The givenliveStreamindicates whether the query should complete when the end of the Event Stream is reached, or if the query should continue processing events as they are stored. When acontextNameis provided the query is executed for that context, instead of the main context for the channel.- Parameters:
queryExpression- a valid Event Stream Query Language expressionliveStream- whether to continue processing live eventscontextName- the name of the context of the event store to query- Returns:
- a ResultStream containing the query results
-
querySnapshotEvents
default ResultStream<EventQueryResultEntry> querySnapshotEvents(String queryExpression, boolean liveStream)
Queries the Event Store for snapshot events using givenqueryExpression. The givenliveStreamindicates whether the query should complete when the end of the Snapshot Event Stream is reached, or if the query should continue processing snapshot events as they are stored.- Parameters:
queryExpression- a valid Event Stream Query Language expressionliveStream- whether to continue processing live snapshot events- Returns:
- a ResultStream containing the query results
-
querySnapshotEvents
default ResultStream<EventQueryResultEntry> querySnapshotEvents(String queryExpression, boolean liveStream, String contextName)
Queries the Event Store for snapshot events using givenqueryExpression. The givenliveStreamindicates whether the query should complete when the end of the Snapshot Event Stream is reached, or if the query should continue processing snapshot events as they are stored. When acontextNameis provided the query is executed for that context, instead of the main context for the channel.- Parameters:
queryExpression- a valid Event Stream Query Language expressionliveStream- whether to continue processing live snapshot eventscontextName- the name of the context of the event store to query- Returns:
- a ResultStream containing the query results
-
createPersistentStream
CompletableFuture<CreateResult> createPersistentStream(String streamId, PersistentStreamProperties creationProperties)
Opens the persistent stream identified bystreamId. If the stream does not exist it will be created with the properties specified increationProperties.- Parameters:
streamId- the unique identification of a persistent streamcreationProperties- properties to initialize the persistent stream if it does not exist yet- Returns:
- a result indicating if the stream has been created or it already existed
-
openPersistentStream
PersistentStream openPersistentStream(String streamId, int bufferSize, int refillBatch, PersistentStreamCallbacks callbacks)
Opens the persistent stream identified bystreamId. Fails if the stream does not exist.- Parameters:
streamId- the unique identification of a persistent streambufferSize- the number of events to buffer locallyrefillBatch- the number of events to be consumed prior to refilling the buffercallbacks- the callbacks that are invoked on persistent stream events- Returns:
- a PersistedStream streaming events per segment
-
openPersistentStream
PersistentStream openPersistentStream(String streamId, int bufferSize, int refillBatch, PersistentStreamCallbacks callbacks, PersistentStreamProperties creationProperties)
Opens the persistent stream identified bystreamId. If the stream does not exist it will be created with the properties specified increationProperties.- Parameters:
streamId- the unique identification of a persistent streambufferSize- the number of events to buffer locallyrefillBatch- the number of events to be consumed prior to refilling the buffercallbacks- the callbacks that are invoked on persistent stream eventscreationProperties- properties to initialize the persistent stream if it does not exist yet- Returns:
- a PersistentStream streaming events per segment
-
deletePersistentStream
CompletableFuture<Void> deletePersistentStream(String streamId)
Deletes a persistent stream. If the stream does not exist the operation completes successfully.- Parameters:
streamId- the unique identification of a persistent stream- Returns:
- a CompletableFuture that completes when the persistent stream is deleted
-
updatePersistentStreamName
CompletableFuture<Void> updatePersistentStreamName(String streamId, String streamName)
Updates the name for a persistent stream.- Parameters:
streamId- the unique identification of a persistent streamstreamName- the new logical name for the stream- Returns:
- a CompletableFuture that completes when the persistent stream is updated
-
setPersistentStreamSegments
CompletableFuture<Void> setPersistentStreamSegments(String streamId, int segments)
Updates the number of segments for a persistent stream.- Parameters:
streamId- the unique identification of a persistent streamsegments- the requested number of segments for the persistent stream- Returns:
- a CompletableFuture that completes when the persistent stream is updated
-
persistentStreams
CompletableFuture<List<StreamStatus>> persistentStreams()
Returns a list of persistent streams with the last confirmed token per segment.- Returns:
- a list of persistent streams
-
resetPersistentStreamAtHead
CompletableFuture<Void> resetPersistentStreamAtHead(String streamId)
Resets the position of a persistent stream to the head (most recent) event in the event store.- Parameters:
streamId- the unique identification of a persistent stream
-
resetPersistentStreamAtTail
CompletableFuture<Void> resetPersistentStreamAtTail(String streamId)
Resets the position of a persistent stream to the first (oldest) event in the event store.- Parameters:
streamId- the unique identification of a persistent stream
-
resetPersistentStreamAtPosition
CompletableFuture<Void> resetPersistentStreamAtPosition(String streamId, long position)
Resets the position of a persistent stream to the event at given position (global index) in the event store.- Parameters:
streamId- the unique identification of a persistent streamposition- the global index of the first event to be returned
-
resetPersistentStreamAtTime
CompletableFuture<Void> resetPersistentStreamAtTime(String streamId, long instant)
Resets the position of a persistent stream to the event at or after the given timestamp in the event store.- Parameters:
streamId- the unique identification of a persistent streaminstant- the timestamp of the first event to be included in the stream
-
-