Beispiel #1
0
        private async Task ExecutePipeline(BasicDeliverEventArgs eventArgs, IConsumingService consumingService)
        {
            Func <BasicDeliverEventArgs, IConsumingService, Task> handle = _messageHandlingService.HandleMessageReceivingEvent;

            foreach (var filter in _handlingFilters.Reverse())
            {
                handle = filter.Execute(handle);
            }

            await handle(eventArgs, consumingService).ConfigureAwait(false);
        }
Beispiel #2
0
 /// <inheritdoc/>
 public async Task Execute(BasicDeliverEventArgs eventArgs, IConsumingService consumingService)
 {
     try
     {
         await ExecutePipeline(eventArgs, consumingService).ConfigureAwait(false);
     }
     catch (Exception exception)
     {
         await ExecuteFailurePipeline(exception, eventArgs, consumingService).ConfigureAwait(false);
     }
 }
 public ChannelDeclarationService(
     IProducingService producingService,
     IConsumingService consumingService,
     IRabbitMqConnectionFactory rabbitMqConnectionFactory,
     IOptions <RabbitMqConnectionOptions> connectionOptions,
     IEnumerable <RabbitMqExchange> exchanges,
     ILoggingService loggingService)
 {
     _producingService          = producingService;
     _consumingService          = consumingService;
     _rabbitMqConnectionFactory = rabbitMqConnectionFactory;
     _connectionOptions         = connectionOptions.Value;
     _exchanges      = exchanges;
     _loggingService = loggingService;
 }
Beispiel #4
0
 /// <inheritdoc />
 public async Task HandleMessageProcessingFailure(Exception exception, BasicDeliverEventArgs eventArgs, IConsumingService consumingService)
 {
     consumingService.Channel.BasicAck(eventArgs.DeliveryTag, false);
     _logger.LogError(new EventId(), exception, $"An error occurred while processing received message with the delivery tag {eventArgs.DeliveryTag}.");
     await HandleFailedMessageProcessing(eventArgs).ConfigureAwait(false);
 }
Beispiel #5
0
        /// <inheritdoc />
        public async Task HandleMessageReceivingEvent(BasicDeliverEventArgs eventArgs, IConsumingService consumingService)
        {
            _logger.LogInformation($"A new message received with deliveryTag {eventArgs.DeliveryTag}.");
            var matchingRoutes = GetMatchingRoutePatterns(eventArgs.Exchange, eventArgs.RoutingKey);

            await ProcessMessageEvent(eventArgs, matchingRoutes).ConfigureAwait(false);

            consumingService.Channel.BasicAck(eventArgs.DeliveryTag, false);
            _logger.LogInformation($"Message processing finished successfully. Acknowledge has been sent with deliveryTag {eventArgs.DeliveryTag}.");
        }
Beispiel #6
0
 public ConsumingHostedService(IConsumingService consumingService)
 {
     _consumingService = consumingService;
 }
Beispiel #7
0
        private async Task ExecuteFailurePipeline(Exception exception, BasicDeliverEventArgs eventArgs, IConsumingService consumingService)
        {
            Func <Exception, BasicDeliverEventArgs, IConsumingService, Task> handle = _messageHandlingService.HandleMessageProcessingFailure;

            foreach (var filter in _exceptionFilters.Reverse())
            {
                handle = filter.Execute(handle);
            }

            await handle(exception, eventArgs, consumingService).ConfigureAwait(false);
        }