public async Task Start() { var position = await _checkpointStore.GetCheckpoint(); _subscription = _isAllStream ? await _client.SubscribeToAllAsync( GetAllStreamPosition(), EventAppeared, subscriptionDropped : SubscriptionDropped) : await _client.SubscribeToStreamAsync( _streamName, GetStreamPosition(), EventAppeared ); FromAll GetAllStreamPosition() => position.HasValue ? FromAll.After(new Position(position.Value, position.Value)) : FromAll.Start; FromStream GetStreamPosition() => position.HasValue ? FromStream.After(position.Value) : FromStream.Start; }
protected override async ValueTask Subscribe(CancellationToken cancellationToken) { var filterOptions = new SubscriptionFilterOptions( Options.EventFilter ?? EventTypeFilter.ExcludeSystemEvents(), Options.CheckpointInterval, async(_, p, ct) => { // This doesn't allow to report tie time gap LastProcessed = new EventPosition(p.CommitPosition, DateTime.Now); await StoreCheckpoint(LastProcessed, ct).NoContext(); } ); var(_, position) = await GetCheckpoint(cancellationToken).NoContext(); var fromAll = position == null ? FromAll.Start : FromAll.After(new Position(position.Value, position.Value)); Subscription = await EventStoreClient.SubscribeToAllAsync( fromAll, HandleEvent, Options.ResolveLinkTos, HandleDrop, filterOptions, Options.Credentials, cancellationToken ).NoContext(); async Task HandleEvent( global::EventStore.Client.StreamSubscription _, ResolvedEvent re, CancellationToken ct ) => await HandleInternal(CreateContext(re, ct)).NoContext(); void HandleDrop( global::EventStore.Client.StreamSubscription _, SubscriptionDroppedReason reason, Exception?ex ) => Dropped(EsdbMappings.AsDropReason(reason), ex); }