private async Task RecoverConsumer(RabbitMqConsumerInfo consumerInfo)
        {
            await Task.Delay(TimeSpan.FromSeconds(5), _cancellationToken);

            _logger.LogWarning("Trying to recover consumer..");

            DestroyConsumer();
            CreateConsumerInternal(consumerInfo);
        }
 public RabbitMqConsumerController(IServiceProvider services
                                   , IConsumerRegistration registration
                                   , RabbitMqConsumerInfo consumerInfo
                                   , IConnection connection
                                   , ILogger <RabbitMqConsumer> logger
                                   , CancellationToken cancellationToken)
 {
     _services          = services;
     _registration      = registration;
     _consumerInfo      = consumerInfo;
     _connection        = connection;
     _logger            = logger;
     _cancellationToken = cancellationToken;
 }
        private void CreateConsumerInternal(RabbitMqConsumerInfo consumerInfo)
        {
            if (_disposing || _disposed)
            {
                return;
            }

            _logger.LogInformation("Creating new consumer. Consumer info: {@ConsumerInfo}.", consumerInfo);

            _consumer = new RabbitMqConsumer(_services, _connection, consumerInfo, _logger);
            _consumer.ChannelCrashed += (_, _) =>
            {
                _logger.LogWarning("Consumer channel crashed. Will try to recreate new.");
                Task.Factory.StartNew(() => RecoverConsumer(consumerInfo), _cancellationToken);
            };

            _cancellationTokenSource = CancellationTokenSource.CreateLinkedTokenSource(_cancellationToken);

            _consumer.Start(_registration, _cancellationTokenSource.Token);
        }
 public virtual List <KeyValuePair <string, object> > Create(BasicDeliverEventArgs @event, ConsumerOptions consumerOptions, RabbitMqConsumerInfo consumerInfo, string correlationId)
 {
     var state = new List <KeyValuePair <string, object> >
     {
         new("CorrelationId", correlationId),
         new("Exchange", consumerInfo.Exchange),
         new("Queue", consumerInfo.Queue),
         new("RoutingKey", consumerInfo.RoutingKey)
     };