private async Task HandleEventAsync(IEventConsumer eventConsumer, StoredEvent storedEvent, string consumerName) { var @event = ParseEvent(storedEvent); if (@event == null) { return; } await DispatchConsumer(@event, eventConsumer, consumerName); await eventConsumerInfoRepository.SetPositionAsync(consumerName, storedEvent.EventPosition, false); }
private async Task SubscribeAsync(IEventConsumer eventConsumer, string position) { var consumerName = eventConsumer.Name; var subscription = eventStore.CreateSubscription(eventConsumer.EventsFilter, position); await subscription.SubscribeAsync(async storedEvent => { await DispatchConsumerAsync(ParseEvent(storedEvent), eventConsumer, eventConsumer.Name); await eventConsumerInfoRepository.SetPositionAsync(eventConsumer.Name, storedEvent.EventPosition, false); }, async exception => { await eventConsumerInfoRepository.StopAsync(consumerName, exception.ToString()); subscription.Dispose(); }); currentSubscription = subscription; }