Exemplo n.º 1
0
        public void HandleBasicDeliver(string consumerTag, ulong deliveryTag, bool redelivered, string exchange, string routingKey,
                                       IBasicProperties properties, ReadOnlyMemory <byte> body)
        {
            byte[] bodyBytes = body.ToArray();

            Task.Run(async() =>
            {
                LogContext.Current = _context.LogContext;

                var context = new RabbitMqReceiveContext(exchange, routingKey, _consumerTag, deliveryTag, bodyBytes, redelivered, properties,
                                                         _context, _receiveSettings, _model, _model.ConnectionContext);

                if (!_pending.TryAdd(deliveryTag, context))
                {
                    LogContext.Warning?.Log("Duplicate BasicDeliver: {DeliveryTag}", deliveryTag);
                }

                var receiveLock = _receiveSettings.NoAck ? default : new RabbitMqReceiveLockContext(_model, deliveryTag);

                                  try
                                  {
                                      await _dispatcher.Dispatch(context, receiveLock).ConfigureAwait(false);
                                  }
                                  catch (Exception exception)
                                  {
                                      context.LogTransportFaulted(exception);
                                  }
                                  finally
                                  {
                                      _pending.TryRemove(deliveryTag, out _);
                                      context.Dispose();
                                  }
            });
        }
Exemplo n.º 2
0
        public void HandleBasicDeliver(string consumerTag, ulong deliveryTag, bool redelivered, string exchange, string routingKey,
                                       IBasicProperties properties, ReadOnlyMemory <byte> body)
        {
            var bodyBytes = body.ToArray();

            Task.Run(async() =>
            {
                LogContext.Current = _context.LogContext;

                var context = new RabbitMqReceiveContext(exchange, routingKey, _consumerTag, deliveryTag, bodyBytes, redelivered, properties,
                                                         _context, _receiveSettings, _model, _model.ConnectionContext);

                var added = _pending.TryAdd(deliveryTag, context);
                if (!added && deliveryTag != 1) // DIRECT REPLY-TO fixed value
                {
                    LogContext.Warning?.Log("Duplicate BasicDeliver: {DeliveryTag}", deliveryTag);
                }

                var receiveLock = _receiveSettings.NoAck ? default : new RabbitMqReceiveLockContext(_model, deliveryTag);

                                  if (_limit != null)
                                  {
                                      await _limit.WaitAsync(context.CancellationToken).ConfigureAwait(false);
                                  }

                                  try
                                  {
                                      await _dispatcher.Dispatch(context, receiveLock).ConfigureAwait(false);
                                  }
                                  catch (Exception exception)
                                  {
                                      context.LogTransportFaulted(exception);
                                  }
                                  finally
                                  {
                                      _limit?.Release();

                                      if (added)
                                      {
                                          _pending.TryRemove(deliveryTag, out _);
                                      }

                                      context.Dispose();
                                  }
            });
        }
        void IBasicConsumer.HandleBasicDeliver(string consumerTag, ulong deliveryTag, bool redelivered, string exchange, string routingKey,
                                               IBasicProperties properties, byte[] body)
        {
            Task.Run(async() =>
            {
                LogContext.Current = _context.LogContext;

                if (IsStopping && _receiveSettings.NoAck == false)
                {
                    await WaitAndAbandonMessage(deliveryTag).ConfigureAwait(false);
                    return;
                }

                var context = new RabbitMqReceiveContext(exchange, routingKey, _consumerTag, deliveryTag, body, redelivered, properties, _context,
                                                         _receiveSettings,
                                                         _model, _model.ConnectionContext);

                if (!_pending.TryAdd(deliveryTag, context))
                {
                    LogContext.Warning?.Log("Duplicate BasicDeliver: {DeliveryTag}", deliveryTag);
                }

                var receiveLock = _receiveSettings.NoAck ? default : new RabbitMqReceiveLockContext(_model, deliveryTag);

                                  try
                                  {
                                      await _dispatcher.Dispatch(context, receiveLock).ConfigureAwait(false);
                                  }
                                  catch (Exception exception)
                                  {
                                      context.LogTransportFaulted(exception);
                                  }
                                  finally
                                  {
                                      _pending.TryRemove(deliveryTag, out _);
                                      context.Dispose();
                                  }
            });
        }