Class EventStoreLiveSubscription
- Namespace
- Excalibur.EventSourcing.Subscriptions
- Assembly
- Excalibur.EventSourcing.dll
Polling-based implementation of IEventSubscription that periodically checks the event store for new events and delivers them to the registered handler.
public sealed class EventStoreLiveSubscription : IEventSubscription, IAsyncDisposable
- Inheritance
-
EventStoreLiveSubscription
- Implements
- Inherited Members
Remarks
This implementation uses a configurable polling interval to detect new events. It tracks the last processed position per subscription and is thread-safe via ConcurrentDictionary<TKey, TValue>.
For production systems with high throughput, consider provider-specific implementations that use native change notification mechanisms (e.g., SQL Server Change Tracking, Cosmos DB Change Feed).
Constructors
EventStoreLiveSubscription(IEventStore, IEventSerializer, EventSubscriptionOptions, ILogger<EventStoreLiveSubscription>)
Initializes a new instance of the EventStoreLiveSubscription class.
public EventStoreLiveSubscription(IEventStore eventStore, IEventSerializer eventSerializer, EventSubscriptionOptions options, ILogger<EventStoreLiveSubscription> logger)
Parameters
eventStoreIEventStoreThe event store to poll for new events.
eventSerializerIEventSerializerThe event serializer for deserializing stored events.
optionsEventSubscriptionOptionsThe subscription options.
loggerILogger<EventStoreLiveSubscription>The logger.
Methods
DisposeAsync()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources asynchronously.
public ValueTask DisposeAsync()
Returns
- ValueTask
A task that represents the asynchronous dispose operation.
SubscribeAsync(string, Func<IReadOnlyList<IDomainEvent>, Task>, CancellationToken)
Subscribes to events on the specified stream, delivering batches to the handler.
public Task SubscribeAsync(string streamId, Func<IReadOnlyList<IDomainEvent>, Task> handler, CancellationToken cancellationToken)
Parameters
streamIdstringThe stream identifier to subscribe to.
handlerFunc<IReadOnlyList<IDomainEvent>, Task>The handler that processes batches of domain events. Events are delivered in order.
cancellationTokenCancellationTokenCancellation token.
Returns
- Task
A task representing the subscription setup.
UnsubscribeAsync(CancellationToken)
Unsubscribes from the event stream, stopping event delivery.
public Task UnsubscribeAsync(CancellationToken cancellationToken)
Parameters
cancellationTokenCancellationTokenCancellation token.
Returns
- Task
A task representing the unsubscribe operation.