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)); }
protected override async Task <EventProcessingResult> TryProcessEventFromConsumerAsync( IEventStreamConsumer consumer, StreamVersion notificationStreamVersion) { try { await ProcessEventBatchAsync(consumer.EnumerateEvents().ToArray()); return(new EventProcessingResult(true, true)); } catch (Exception exception) { ListenerLogger.Error( exception, "Processing event batch from stream {Stream} failed.", consumer.StreamName); return(new EventProcessingResult(false, false)); } }
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); }
protected abstract Task <EventProcessingResult> TryProcessEventFromConsumerAsync( IEventStreamConsumer consumer, StreamVersion notificationStreamVersion);
protected override Task <EventProcessingResult> TryProcessEventFromConsumerAsync(IEventStreamConsumer consumer, StreamVersion notificationStreamVersion) { return(ProcessingCompleted ? Task.FromResult(new EventProcessingResult(true, true)) : Task.FromResult(new EventProcessingResult(false, false))); }
public static Task CommitProcessedStreamVersionAsync(this IEventStreamConsumer consumer) { Require.NotNull(consumer, "consumer"); return(consumer.CommitProcessedStreamVersionAsync(false)); }