Пример #1
0
            private void Rollback(ulong deliveryTag, Exception e)
            {
                if (_container.IsChannelTransacted)
                {
                    RabbitUtils.RollbackIfNecessary(Model);
                }

                if (AckRequired || ContainerUtils.IsRejectManual(e))
                {
                    try
                    {
                        if (MessagesPerAck > 1)
                        {
                            lock (_lock)
                            {
                                if (PendingAcks > 0)
                                {
                                    SendAck(DateTimeOffset.Now.ToUnixTimeMilliseconds());
                                }
                            }
                        }

                        Model.BasicNack(deliveryTag, true, ContainerUtils.ShouldRequeue(_container.DefaultRequeueRejected, e, _logger));
                    }
                    catch (IOException e1)
                    {
                        _logger?.LogError("Failed to nack message", e1);
                    }
                }

                if (_container.IsChannelTransacted)
                {
                    RabbitUtils.CommitIfNecessary(Model);
                }
            }
Пример #2
0
 protected virtual void PrepareHolderForRollback(RabbitResourceHolder resourceHolder, Exception exception)
 {
     if (resourceHolder != null)
     {
         resourceHolder.RequeueOnRollback = AlwaysRequeueWithTxManagerRollback ||
                                            ContainerUtils.ShouldRequeue(DefaultRequeueRejected, exception, _logger);
     }
 }
 private void AsyncFailure(IMessage request, RC.IModel channel, Exception exception)
 {
     _logger?.LogError(exception, "Async method was completed with an exception for {request} ", request);
     try
     {
         channel.BasicNack(request.Headers.DeliveryTag().Value, false, ContainerUtils.ShouldRequeue(DefaultRequeueRejected, exception, _logger));
     }
     catch (Exception e)
     {
         _logger?.LogError(e, "Failed to nack message");
     }
 }
Пример #4
0
        public void RollbackOnExceptionIfNecessary(Exception ex)
        {
            bool ackRequired = !AcknowledgeMode.IsAutoAck() && (!AcknowledgeMode.IsManual() || ContainerUtils.IsRejectManual(ex));

            try
            {
                if (Transactional)
                {
                    Logger?.LogDebug(ex, "Initiating transaction rollback on application exception");
                    RabbitUtils.RollbackIfNecessary(Channel);
                }

                if (ackRequired)
                {
                    if (DeliveryTags.Count > 0)
                    {
                        ulong deliveryTag = DeliveryTags.Max();
                        Channel.BasicNack(deliveryTag, true, ContainerUtils.ShouldRequeue(DefaultRequeueRejected, ex, Logger));
                    }

                    if (Transactional)
                    {
                        // Need to commit the reject (=nack)
                        RabbitUtils.CommitIfNecessary(Channel);
                    }
                }
            }
            catch (Exception e)
            {
                Logger?.LogError(ex, "Application exception overridden by rollback exception");
                throw RabbitExceptionTranslator.ConvertRabbitAccessException(e); // NOSONAR stack trace loss
            }
            finally
            {
                DeliveryTags.Clear();
            }
        }
Пример #5
0
 public void TestMustNotRequeue()
 {
     Assert.False(ContainerUtils.ShouldRequeue(
                      true,
                      new ListenerExecutionFailedException(string.Empty, new RabbitRejectAndDontRequeueException("no requeue"))));
 }
Пример #6
0
 public void TestMustRequeue()
 {
     Assert.True(ContainerUtils.ShouldRequeue(
                     false,
                     new ListenerExecutionFailedException(string.Empty, new ImmediateRequeueException("requeue"))));
 }
Пример #7
0
 private void AsyncFailure(Message request, IModel channel, Exception exception)
 {
     _logger?.LogError("Future or Mono was completed with an exception for " + request, exception);
     try
     {
         channel.BasicNack(request.MessageProperties.DeliveryTag.Value, false, ContainerUtils.ShouldRequeue(DefaultRequeueRejected, exception, _logger));
     }
     catch (IOException e)
     {
         _logger?.LogError("Failed to nack message", e);
     }
 }