Class PersistentStreamConnection
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.
close() still delivers every event already buffered locally at the moment it is called to the consumer, and
only retires that consumer, in favor of a no-op, once all of it has been delivered.
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, PersistentStreamContextCustomizer contextCustomizer, int batchSize, @Nullable String context) Instantiates aPersistentStreamConnectionplacing additional resources on theProcessingContextof every batch through the givencontextCustomizer. -
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, PersistentStreamContextCustomizer contextCustomizer, int batchSize, @Nullable String context) Instantiates aPersistentStreamConnectionplacing additional resources on theProcessingContextof every batch through the givencontextCustomizer.- 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 factorycontextCustomizer- the customizer placing resources on theProcessingContextof every batch, invoked once per batch before any of its events is consumed, returning the context that batch is consumed withbatchSize- 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.Events already buffered locally for a segment at the moment this method is called are still delivered to the consumer supplied to
open(BiFunction). The consumer is only retired, in favor of a no-op, once every currently open segment has confirmed its local buffer is fully drained. Otherwise, those buffered events would be acknowledged to Axon Server without ever reaching a real consumer.
-