protected override async Task <EventProcessingResult> TryProcessEventFromConsumerAsync( IEventStreamConsumer consumer, StreamVersion notificationStreamVersion) { foreach (var journaledEvent in consumer.EnumerateEvents()) { var failed = false; try { await ProcessEventAsync(journaledEvent); } catch (Exception exception) { ListenerLogger.Error( exception, "Processing event {EventId} of type {EventType} from stream {Stream} failed.", journaledEvent.EventId, journaledEvent.EventTypeName, consumer.StreamName); failed = true; } if (failed) { await consumer.CommitProcessedStreamVersionAsync(skipCurrent : true); return(new EventProcessingResult(false, false)); } } return(new EventProcessingResult(true, true)); }
private async Task <bool> ReceiveAndProcessEventsAsync(EventStreamUpdated notification, IEventStreamConsumer consumer) { var retryProcessing = true; var commitProcessing = false; var receivingResult = await consumer.ReceiveEventsAsync(); if (receivingResult == ReceivingResultCode.EventsReceived) { var processingResult = await TryProcessEventFromConsumerAsync(consumer, notification.ToVersion); retryProcessing = !processingResult.IsSuccessful; commitProcessing = processingResult.ShouldCommitProcessing; } else if (receivingResult == ReceivingResultCode.EmptyStream) { retryProcessing = false; } if (commitProcessing) { await consumer.CommitProcessedStreamVersionAsync(); } if (retryProcessing) { ListenerLogger.Warning( "Processing notification ({NotificationId}, {NotificationType}) was unsuccessful {Code}. Going to try later.", notification.NotificationId, notification.NotificationType, receivingResult); } return(retryProcessing); }
public static Task CommitProcessedStreamVersionAsync(this IEventStreamConsumer consumer) { Require.NotNull(consumer, "consumer"); return(consumer.CommitProcessedStreamVersionAsync(false)); }