Ejemplo n.º 1
0
        private async Task Handle(ProcessStreamEvent processStreamEvent)
        {
            if (_handlers.Count == 0)
            {
                return;
            }

            _lastProcessedMessagePosition = processStreamEvent.Message.Position;

            _logger.LogTrace(
                "Handling message {MessageType} at {Position}",
                processStreamEvent.Message.Type,
                processStreamEvent.Message.Position);


            foreach (var projectionName in _handlers.Keys.ToReadOnlyList())
            {
                try
                {
                    await _handlers[projectionName](processStreamEvent.Message, processStreamEvent.CancellationToken);
                }
                catch (ConnectedProjectionMessageHandlingException messageHandlingException)
                {
                    var projectionInError = messageHandlingException.RunnerName;
                    _logger.LogError(
                        messageHandlingException.InnerException,
                        "Handle message Subscription {RunnerName} failed because an exception was thrown when handling the message at {Position}.",
                        projectionInError,
                        messageHandlingException.RunnerPosition);

                    _logger.LogWarning(
                        "Stopped faulty subscribed projection {Projection}",
                        projectionInError);

                    _handlers.Remove(projectionInError);
                }
                catch (Exception exception)
                {
                    _logger.LogError(
                        exception,
                        "Unhandled exception in Handle:{Command}.", nameof(ProcessStreamEvent));

                    _logger.LogInformation(
                        "Removing faulty subscribed projection {Projection}",
                        projectionName);

                    _handlers.Remove(projectionName);
                }
            }
        }
Ejemplo n.º 2
0
        private async Task Handle(ProcessStreamEvent processStreamEvent)
        {
            if (_handlers.Count == 0)
            {
                return;
            }

            _lastProcessedMessagePosition = processStreamEvent.Message.Position;

            _logger.LogTrace(
                "Handling message {MessageType} at {Position}",
                processStreamEvent.Message.Type,
                processStreamEvent.Message.Position);


            foreach (var projection in _handlers.Keys.ToReadOnlyList())
            {
                try
                {
                    await _handlers[projection](processStreamEvent.Message, processStreamEvent.CancellationToken);
                }
                catch (ConnectedProjectionMessageHandlingException e)
                    when(e.InnerException is StreamGapDetectedException)
                    {
                        var projectionInError = e.Projection;

                        _logger.LogWarning(
                            "Detected gap in the message stream for subscribed projection. Unsubscribed projection {Projection} and queued restart in {RestartDelay} seconds.",
                            projectionInError,
                            _subscriptionStreamGapStrategy.Settings.RetryDelayInSeconds);

                        _handlers.Remove(projectionInError);

                        _commandBus.Queue(
                            new Restart(
                                projectionInError,
                                TimeSpan.FromSeconds(_subscriptionStreamGapStrategy.Settings.RetryDelayInSeconds)));
                    }
                catch (ConnectedProjectionMessageHandlingException messageHandlingException)
                {
                    var projectionInError = messageHandlingException.Projection;
                    _logger.LogError(
                        messageHandlingException.InnerException,
                        "Handle message Subscription {Projection} failed because an exception was thrown when handling the message at {Position}.",
                        projectionInError,
                        messageHandlingException.RunnerPosition);

                    _logger.LogWarning(
                        "Stopped faulty subscribed projection {Projection}",
                        projectionInError);

                    _handlers.Remove(projectionInError);
                }
                catch (Exception exception)
                {
                    _logger.LogError(
                        exception,
                        "Unhandled exception in Handle:{Command}.", nameof(ProcessStreamEvent));

                    _logger.LogInformation(
                        "Removing faulty subscribed projection {Projection}",
                        projection);

                    _handlers.Remove(projection);
                }
            }
        }