Class PersistentStreamConnection
java.lang.Object
io.axoniq.framework.axonserver.connector.event.PersistentStreamConnection
A connection instance receiving the events for a persistent stream to pass on in batches to an event consumer.
Opens a gRPC connection to Axon Server via open(BiFunction) and invokes the supplied
BiFunction for each batch. The batch consumer returns a CompletableFuture that must complete before
the token for the last event in the batch is acknowledged to Axon Server. On consumer failure the batch is retried
with exponential back-off.
This is an internal helper for the PersistentStreamEventSource managing the gRPC based persistent stream
with Axon Server. This class is usually not used directly by users.
- Since:
- 5.2.0
- Author:
- Marc Gathier, Jakob Hatzl
-
Constructor Summary
ConstructorsConstructorDescriptionPersistentStreamConnection(String streamId, AxonServerConnectionManager connectionManager, AxonServerConfiguration serverConfig, EventConverter converter, io.axoniq.axonserver.connector.event.PersistentStreamProperties persistentStreamProperties, ScheduledExecutorService scheduler, UnitOfWorkFactory unitOfWorkFactory, int batchSize, @Nullable String context) Instantiates aPersistentStreamConnectionfalling back to thedefault event type resolverfor message type resolution.PersistentStreamConnection(String streamId, AxonServerConnectionManager connectionManager, AxonServerConfiguration serverConfig, EventConverter converter, EventTypeResolver eventTypeResolver, io.axoniq.axonserver.connector.event.PersistentStreamProperties persistentStreamProperties, ScheduledExecutorService scheduler, UnitOfWorkFactory unitOfWorkFactory, int batchSize, @Nullable String context) Instantiates aPersistentStreamConnection. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Closes the persistent stream connection to Axon Server.voidopen(BiFunction<List<? extends EventMessage>, ProcessingContext, CompletableFuture<?>> consumer) Initiates the connection to Axon Server and starts delivering events to the givenconsumer.
-
Constructor Details
-
PersistentStreamConnection
public PersistentStreamConnection(String streamId, AxonServerConnectionManager connectionManager, AxonServerConfiguration serverConfig, EventConverter converter, io.axoniq.axonserver.connector.event.PersistentStreamProperties persistentStreamProperties, ScheduledExecutorService scheduler, UnitOfWorkFactory unitOfWorkFactory, int batchSize, @Nullable String context) Instantiates aPersistentStreamConnectionfalling back to thedefault event type resolverfor message type resolution.- Parameters:
streamId- the unique identifier of the persistent streamconnectionManager- the Axon Server connection managerserverConfig- the Axon Server configurationconverter- the event converter used to deserialize event payloadspersistentStreamProperties- the properties for the persistent streamscheduler- the scheduler thread pool to schedule tasksunitOfWorkFactory- the unit of work factorybatchSize- the maximum number of events to collect per batchcontext- the Axon Server context to connect to, ornullto useAxonServerConfiguration.getContext()
-
PersistentStreamConnection
public PersistentStreamConnection(String streamId, AxonServerConnectionManager connectionManager, AxonServerConfiguration serverConfig, EventConverter converter, EventTypeResolver eventTypeResolver, io.axoniq.axonserver.connector.event.PersistentStreamProperties persistentStreamProperties, ScheduledExecutorService scheduler, UnitOfWorkFactory unitOfWorkFactory, int batchSize, @Nullable String context) Instantiates aPersistentStreamConnection.- Parameters:
streamId- the unique identifier of the persistent streamconnectionManager- the Axon Server connection managerserverConfig- the Axon Server configurationconverter- the event converter used to deserialize event payloadseventTypeResolver- the event type resolver used to resolve the type on inbound eventspersistentStreamProperties- the properties for the persistent streamscheduler- the scheduler thread pool to schedule tasksunitOfWorkFactory- the unit of work factorybatchSize- the maximum number of events to collect per batchcontext- the Axon Server context to connect to, ornullto useAxonServerConfiguration.getContext()
-
-
Method Details
-
open
public void open(BiFunction<List<? extends EventMessage>, ProcessingContext, CompletableFuture<?>> consumer) Initiates the connection to Axon Server and starts delivering events to the givenconsumer.The stream can be opened with only a single consumer at a time. After a previous
close(), the stream may be reopened by calling this method again.- Parameters:
consumer- the consumer of batches of event messages; to allow providing tracking and replay information per event, it receives each event in a single callbackProcessingContextenriched with the currentTrackingTokenand, when available, aggregate identity information, and must return aCompletableFuturethat completes when the event has been processed; events are still processed in batches as configured through thebatchSizeconstructor argument, the persistent stream connection takes care of creating and spanning a unit of work over all events belonging to a single batch- Throws:
IllegalStateException- if the stream was already opened
-
close
public void close()Closes the persistent stream connection to Axon Server.
-