Пример #1
0
        public void LogInformationWithMessageInfo_SingleInboundMessage_InformationLogged()
        {
            _integrationLogger.LogInformationWithMessageInfo(
                new EventId(42, "test"),
                "Log message",
                _singleInboundMessageContext);

            const string expectedMessage =
                "Log message | " +
                "endpointName: TestActual, " +
                "failedAttempts: 1, " +
                "messageType: Something.Xy, " +
                "messageId: 1234, " +
                "offset-in: 9";

            _logger.Received(LogLevel.Information, null, expectedMessage);
        }
Пример #2
0
            protected override async Task <bool> ApplyPolicyAsync(ConsumerPipelineContext context, Exception exception)
            {
                Check.NotNull(context, nameof(context));
                Check.NotNull(exception, nameof(exception));

                _logger.LogInformationWithMessageInfo(
                    IntegrationEventIds.MessageMoved,
                    $"The message will be moved to endpoint '{_endpoint.Name}'.",
                    context);

                await PublishToNewEndpointAsync(context.Envelope, exception).ConfigureAwait(false);

                await context.TransactionManager.RollbackAsync(exception, true).ConfigureAwait(false);

                return(true);
            }
Пример #3
0
            protected override async Task <bool> ApplyPolicyAsync(ConsumerPipelineContext context, Exception exception)
            {
                Check.NotNull(context, nameof(context));
                Check.NotNull(exception, nameof(exception));

                await context.TransactionManager.RollbackAsync(exception, stopConsuming : false).ConfigureAwait(false);

                await ApplyDelayAsync(context).ConfigureAwait(false);

                _logger.LogInformationWithMessageInfo(
                    IntegrationEventIds.RetryMessageProcessing,
                    "The message(s) will be processed again.",
                    context);

                return(true);
            }
        private async Task <bool> CheckIsAlreadyProcessedAsync(ConsumerPipelineContext context)
        {
            if (context.Envelope.Endpoint.ExactlyOnceStrategy == null)
            {
                return(false);
            }

            var strategyImplementation = context.Envelope.Endpoint.ExactlyOnceStrategy.Build(context.ServiceProvider);

            if (!await strategyImplementation.CheckIsAlreadyProcessedAsync(context).ConfigureAwait(false))
            {
                return(false);
            }

            _logger.LogInformationWithMessageInfo(
                IntegrationEventIds.MessageAlreadyProcessed,
                "Message is being skipped since it was already processed.",
                context);

            return(true);
        }
Пример #5
0
        private async Task ExecutePipelineAsync(
            ProducerPipelineContext context,
            ProducerBehaviorHandler finalAction,
            int stepIndex = 0)
        {
            if (_behaviors.Count > 0 && stepIndex < _behaviors.Count)
            {
                await _behaviors[stepIndex].HandleAsync(
                    context,
                    nextContext => ExecutePipelineAsync(nextContext, finalAction, stepIndex + 1))
                .ConfigureAwait(false);
            }
            else
            {
                await finalAction(context).ConfigureAwait(false);

                _logger.LogInformationWithMessageInfo(
                    IntegrationEventIds.MessageProduced,
                    "Message produced.",
                    context.Envelope);
            }
        }