Ejemplo n.º 1
0
        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));
            }
        }
        public async Task On(EventStreamUpdated notification)
        {
            Require.NotNull(notification, "notification");

            AssertSubscriptionWasBound();

            m_processingCountdown.AddCount();

            var retryProcessing = false;

            try
            {
                var consumer = await m_subscription.CreateSubscriptionConsumerAsync(notification.StreamName);

                retryProcessing = await ReceiveAndProcessEventsAsync(notification, consumer);

                await consumer.CloseAsync();
            }
            catch (Exception exception)
            {
                ListenerLogger.Error(
                    exception,
                    "Processing notification ({NotificationId}, {NotificationType}) from {Stream} failed.",
                    notification.NotificationId,
                    notification.NotificationType,
                    notification.StreamName);

                retryProcessing = true;
            }
            finally
            {
                m_processingCountdown.Signal();
            }

            if (retryProcessing)
            {
                await m_subscription.RetryNotificationProcessingAsync(notification);
            }
        }