Ejemplo n.º 1
0
        private async Task ProcessMessageAsync(
            OutboxStoredMessage message,
            IOutboxReader outboxReader,
            IServiceProvider serviceProvider)
        {
            try
            {
                var endpoint = GetTargetEndpoint(message.MessageType, message.EndpointName, serviceProvider);
                await ProduceMessageAsync(message.Content, message.Headers, endpoint).ConfigureAwait(false);

                await outboxReader.AcknowledgeAsync(message).ConfigureAwait(false);
            }
            catch (Exception ex)
            {
                _logger.LogErrorWithMessageInfo(
                    IntegrationEventIds.ErrorProducingOutboxStoredMessage,
                    ex,
                    "Failed to produce the message in the outbox.",
                    new OutboundEnvelope(message.Content, message.Headers, new LoggingEndpoint(message.EndpointName)));

                await outboxReader.RetryAsync(message).ConfigureAwait(false);

                // Rethrow if message order has to be preserved, otherwise go ahead with next message in the queue
                if (_enforceMessageOrder)
                {
                    throw;
                }
            }
        }
Ejemplo n.º 2
0
        private static async Task AcknowledgeAllAsync(
            IOutboxReader outboxReader,
            List <OutboxStoredMessage> messages,
            ConcurrentBag <OutboxStoredMessage> failedMessages)
        {
            await outboxReader.RetryAsync(failedMessages).ConfigureAwait(false);

            await outboxReader.AcknowledgeAsync(messages.Where(message => !failedMessages.Contains(message)))
            .ConfigureAwait(false);
        }
Ejemplo n.º 3
0
        private async Task ProcessMessageAsync(
            OutboxStoredMessage message,
            ConcurrentBag <OutboxStoredMessage> failedMessages,
            IOutboxReader outboxReader,
            IServiceProvider serviceProvider)
        {
            try
            {
                var endpoint = GetTargetEndpoint(message.MessageType, message.EndpointName, serviceProvider);

                await ProduceMessageAsync(
                    message.Content,
                    message.Headers,
                    endpoint,
                    message.ActualEndpointName ?? endpoint.Name,
                    _ =>
                {
                    Interlocked.Decrement(ref _pendingProduceOperations);
                },
                    exception =>
                {
                    failedMessages.Add(message);
                    Interlocked.Decrement(ref _pendingProduceOperations);

                    _logger.LogErrorProducingOutboxStoredMessage(
                        new OutboundEnvelope(
                            message.Content,
                            message.Headers,
                            new LoggingEndpoint(message.EndpointName)),
                        exception);
                })
                .ConfigureAwait(false);
            }
            catch (Exception ex)
            {
                failedMessages.Add(message);
                Interlocked.Decrement(ref _pendingProduceOperations);

                _logger.LogErrorProducingOutboxStoredMessage(
                    new OutboundEnvelope(
                        message.Content,
                        message.Headers,
                        new LoggingEndpoint(message.EndpointName)),
                    ex);

                await outboxReader.RetryAsync(message).ConfigureAwait(false);

                // Rethrow if message order has to be preserved, otherwise go ahead with next message in the queue
                if (_enforceMessageOrder)
                {
                    throw;
                }
            }
        }