Ejemplo n.º 1
0
        private void BasicNacksHandler(object sender, BasicNackEventArgs args)
        {
            if (!(sender is IModel channel))
            {
                return;
            }

            foreach (JobInfo job in LIST_OF_JOBS)
            {
                if (job.Channel.ChannelNumber == channel.ChannelNumber)
                {
                    int deliveryTag = (int)args.DeliveryTag;

                    FileLogger.Log($"Channel #{channel.ChannelNumber}: Nack delivery tag = {args.DeliveryTag}, multiple = {args.Multiple}");

                    int messagesSent = 0;

                    foreach (BatchInfo batch in job.Batches)
                    {
                        messagesSent += batch.MessagesSent;

                        if (deliveryTag <= messagesSent)
                        {
                            batch.IsNacked = true;
                            break;
                        }
                    }
                    break;
                }
            }
        }
Ejemplo n.º 2
0
        private void Channel_BasicNacks(object sender, BasicNackEventArgs e)
        {
            _outstandingConfirms.TryGetValue(e.DeliveryTag, out string body);
            _logger.LogError($"Message with body {body} has been nack-ed. Sequence number: {e.DeliveryTag}, multiple: {e.Multiple}");

            ClearOutstandingConfirms(e.DeliveryTag, e.Multiple);
        }
        void Channel_BasicNacks(object sender, BasicNackEventArgs e)
        {
            TaskEx.StartNew(new EventState {
                Messages = messages, DeliveryTag = e.DeliveryTag, Multiple = e.Multiple
            }, state =>
            {
                var eventState = (EventState)state;

                if (!eventState.Multiple)
                {
                    TaskCompletionSource <bool> tcs;
                    eventState.Messages.TryRemove(eventState.DeliveryTag, out tcs);

                    tcs?.SetException(new Exception("Message rejected by broker."));
                }
                else
                {
                    foreach (var message in eventState.Messages)
                    {
                        if (message.Key <= eventState.DeliveryTag)
                        {
                            TaskCompletionSource <bool> tcs;
                            eventState.Messages.TryRemove(message.Key, out tcs);

                            tcs?.SetException(new Exception("Message rejected by broker."));
                        }
                    }
                }
            });
        }
Ejemplo n.º 4
0
 public void OnBasicNack(object sender, BasicNackEventArgs e) => OnBrokerCommandArrival(
     e.DeliveryTag,
     e.Multiple,
     "Messages {0}-{1} failed to be published.",
     "Message {0} failed to be published.",
     ref _lastUnconfirmedId
     );
Ejemplo n.º 5
0
        public void Should_mark_failure()
        {
            const int sequenceNumber = 34456;

            channel.Stub(x => x.NextPublishSeqNo).Return(sequenceNumber);

            var success = false;
            var failure = false;

            Action successCallback = () => success = true;
            Action failureCallback = () => failure = true;

            publisherConfirms.RegisterCallbacks(channel, successCallback, failureCallback);

            var args = new BasicNackEventArgs
            {
                DeliveryTag = sequenceNumber,
                Multiple    = false
            };

            publisherConfirms.FailedPublish(channel, args);

            success.ShouldBeFalse();
            failure.ShouldBeTrue();
        }
Ejemplo n.º 6
0
 private void ChannelOnBasicNacks(object sender, BasicNackEventArgs ea)
 {
     if (_OutstandingConfirms.TryGetValue(ea.DeliveryTag, out var body))
     {
         _Logger.LogWarning("Consumer cant process message. Body: {0}", body);
         CleanOutstandingConfirms(ea.DeliveryTag);
     }
 }
Ejemplo n.º 7
0
        public void FailedPublish(IModel channel, BasicNackEventArgs args)
        {
            if (args == null)
            {
                throw new ArgumentNullException("args");
            }

            ProcessArgsAndRun(args.Multiple, args.DeliveryTag, x => x.Failure());
        }
Ejemplo n.º 8
0
 private void OnPublishFailed(object sender, BasicNackEventArgs e)
 {
     if (_pendingConfirmations.TryGetValue(e.DeliveryTag, out Guid messageId))
     {
         OnMessagePublished?.Invoke(false, messageId);
         _pendingConfirmations.TryRemove(e.DeliveryTag, out Guid msgId);
         s_logger.LogDebug("Failed to publish message: {MessageId}", messageId);
     }
 }
Ejemplo n.º 9
0
        private void HandleNack(IModel model, BasicNackEventArgs args)
        {
            var confirmIds = GetConfirmIds(args.DeliveryTag, args.Multiple);

            if (confirmIds.Count > 0)
            {
                _publisherConfirmSettings.Nacktion(confirmIds);
            }
        }
Ejemplo n.º 10
0
        // TODO: do something useful with not acknowledge messages, retry?
        public void NotAcknowledge(object sender, BasicNackEventArgs e)
        {
            OutStandingConfirms.TryGetValue(e.DeliveryTag, out var body);

            this.logger.LogWarning(
                $"Message with body {body} has been nack-ed. Sequence number: {e.DeliveryTag}, multiple: {e.Multiple}");

            this.CleanOutstandingConfirms(e.DeliveryTag, e.Multiple);
        }
 private void BasicNacks(object sender, BasicNackEventArgs args)
 {
     foreach (var seqNo in _pending.Keys)
     {
         if (IsMatch(args.DeliveryTag, args.Multiple, seqNo) && _pending.TryRemove(seqNo, out var tcs))
         {
             tcs.TrySetException(new RabbitNackException());
         }
     }
 }
Ejemplo n.º 12
0
 private void PublishModelOnBasicNacks(IModel model, BasicNackEventArgs args)
 {
     if (args.Multiple)
     {
         log.WarnFormat("Broker nacked all deliveries up to and including #{0}", args.DeliveryTag);
     }
     else
     {
         log.WarnFormat("Broker nacked delivery #{0}", args.DeliveryTag);
     }
 }
Ejemplo n.º 13
0
 // nack的时候通常broker那里可能出了什么状况,log一波(暂时不考虑重试了)
 // 消息的状态置为终结态Error
 private void Channel_BasicNacks(object sender, BasicNackEventArgs e)
 {
     if (e.Multiple)
     {
         _tracker.SetMultipleStatus(e.DeliveryTag, MessageState.Error);
     }
     else
     {
         _tracker.SetStatus(e.DeliveryTag, MessageState.Error, remark: string.Empty);
     }
 }
Ejemplo n.º 14
0
        public void Handler(object sender, BasicNackEventArgs e, IPublishedMessageStore publishedMessageStore)
        {
            using (var tx = publishedMessageStore.BeginTransaction())
            {
                RmqPublishMessage targetMessage = publishedMessageStore.GetByDeliveryTag(e.DeliveryTag);

                targetMessage.Status = MessageStatusConstants.Failed;

                publishedMessageStore.Commit(tx);
            }
        }
Ejemplo n.º 15
0
 private void NackCallback <T>(BasicNackEventArgs ea, MessageTracker <T> messageTracker)
 {
     if (ea.Multiple)
     {
         messageTracker.SetMultipleStatus(ea.DeliveryTag, SendStatus.Failed);
     }
     else
     {
         messageTracker.SetStatus(ea.DeliveryTag, SendStatus.Failed);
     }
 }
Ejemplo n.º 16
0
 private void BasicNacks(IModel model, BasicNackEventArgs args)
 {
     foreach (ulong seqNo in GetSeqNos(args.DeliveryTag, args.Multiple))
     {
         TaskCompletionSource <object> tcs;
         if (_pending.TryRemove(seqNo, out tcs))
         {
             tcs.TrySetException(new RabbitNackException());
         }
     }
 }
Ejemplo n.º 17
0
        private void OnChannelNacked(
            BasicNackEventArgs args)
        {
            this.c_logger.WarnFormat("OnChannelNacked Starting, is multiple = {0} and delivery tag = {1}", args.Multiple, args.DeliveryTag);

            this.ProcessDeliveryTags(
                args.Multiple,
                args.DeliveryTag,
                publication => publication.SetResult(PublicationResultStatus.Nacked));

            this.c_logger.WarnFormat("OnChannelNacked Completed, is multiple = {0} and delivery tag = {1}", args.Multiple, args.DeliveryTag);
        }
Ejemplo n.º 18
0
        public void OnBasicNacks(IModel model, BasicNackEventArgs args)
        {
            receipts.ProcessReceipts(args.Multiple, args.DeliveryTag, receipt =>
            {
                // Extract the failed message
                var failedMessage = receipt.Message;

                // Mark this receipt as failed
                receipt.Failed(PublishFailureReason.Nack);

                // And ask the publisher fault strategy what to do with this
                publisherFailureStrategy.OnFailure(this, failedMessage, receipt);
            });
        }
Ejemplo n.º 19
0
 void Channel_BasicNacks(object sender, BasicNackEventArgs e)
 {
     if (!e.Multiple)
     {
         SetException(e.DeliveryTag, "Message rejected by broker.");
     }
     else
     {
         foreach (var message in messages)
         {
             if (message.Key <= e.DeliveryTag)
             {
                 SetException(message.Key, "Message rejected by broker.");
             }
         }
     }
 }
Ejemplo n.º 20
0
        private void OnChannelNack(
            IModel channel,
            BasicNackEventArgs args)
        {
            TaskCompletionSource <string> _taskCompletionSource;
            var _confirmedDeliveryTags = this.c_unconfirmedMessages.Keys.Where(deliveryTag => deliveryTag <= args.DeliveryTag);

            foreach (var _confirmedDeliveryTag in _confirmedDeliveryTags)
            {
                if (!this.c_unconfirmedMessages.TryRemove(_confirmedDeliveryTag, out _taskCompletionSource))
                {
                    throw new ApplicationException("Could not remove delivery tag entry");
                }

                _taskCompletionSource.SetResult((string)_taskCompletionSource.Task.AsyncState);
            }
        }
Ejemplo n.º 21
0
        void HandleNack(IModel model, BasicNackEventArgs args)
        {
#if NET40
            IEnumerable <ulong> ids = Enumerable.Repeat(args.DeliveryTag, 1);
            if (args.Multiple)
            {
                ids = _confirms.GetAllKeys().Where(x => x <= args.DeliveryTag);
            }

            var exception = new InvalidOperationException("Publish was nacked by the broker");

            foreach (ulong id in ids)
            {
                _confirms[id].TrySetException(exception);
                _confirms.Remove(id);
            }
#endif
        }
 private void OnBasicNack(object sender, BasicNackEventArgs e)
 {
     if (!e.Multiple)
     {
         messagesInFlight.TryGetValue(e.DeliveryTag, out var message);
         message?.Nack((IModel)sender);
     }
     else
     {
         foreach (var message in messagesInFlight.Values)
         {
             // See comment in Basic Ack event handler
             if (message.SequenceNumber <= e.DeliveryTag)
             {
                 message.Nack((IModel)sender);
             }
         }
     }
 }
Ejemplo n.º 23
0
 void OnBasicNacks(object model, BasicNackEventArgs args)
 {
     if (args.Multiple)
     {
         ulong[] ids = _published.Keys.Where(x => x <= args.DeliveryTag).ToArray();
         foreach (var id in ids)
         {
             if (_published.TryRemove(id, out var value))
             {
                 value.Nack();
             }
         }
     }
     else
     {
         if (_published.TryRemove(args.DeliveryTag, out var value))
         {
             value.Nack();
         }
     }
 }
Ejemplo n.º 24
0
 private void OnBasicNacks(object?model, BasicNackEventArgs args)
 {
     if (args.Multiple)
     {
         var ids = _publishTasks.Keys.Where(x => x <= args.DeliveryTag).ToArray();
         foreach (var id in ids.AsParallel())
         {
             if (_publishTasks.TryRemove(id, out var publishTaskInfo))
             {
                 publishTaskInfo.Nack();
             }
         }
     }
     else
     {
         if (_publishTasks.TryRemove(args.DeliveryTag, out var publishTaskInfo))
         {
             publishTaskInfo.Nack();
         }
     }
 }
Ejemplo n.º 25
0
        public void Should_mark_success_up_to_sequence_number_when_multiple_is_true()
        {
            const string expectedOutput = "Success0 Success1 Success2 Success3 Success4 Success5 --multiple ack of 5 complete --Failure6 Failure7 Failure8 ";
            var          writer         = new StringWriter();
            //var writer = Console.Out;

            Action <ulong> registerCallback = sequenceNumber =>
            {
                var model = MockRepository.GenerateStub <IModel>();
                model.Stub(x => x.NextPublishSeqNo).Return(sequenceNumber);
                publisherConfirms.RegisterCallbacks(model,
                                                    () => writer.Write("Success{0} ", sequenceNumber),
                                                    () => writer.Write("Failure{0} ", sequenceNumber));
            };

            for (ulong i = 0; i < 10; i++)
            {
                registerCallback(i);
            }

            var args = new BasicAckEventArgs
            {
                DeliveryTag = 5, // should callback success up to and including seq no 5
                Multiple    = true
            };

            publisherConfirms.SuccessfulPublish(channel, args);

            writer.Write("--multiple ack of 5 complete --");

            var args2 = new BasicNackEventArgs
            {
                DeliveryTag = 8, // should callback failure for 6, 7, 8
                Multiple    = true
            };

            publisherConfirms.FailedPublish(channel, args2);

            writer.ToString().ShouldEqual(expectedOutput);
        }
Ejemplo n.º 26
0
        public void FailedPublish(IModel channel, BasicNackEventArgs args)
        {
            Preconditions.CheckNotNull(args, "args");

            ProcessArgsAndRun(args.Multiple, args.DeliveryTag, x => x.Failure());
        }
Ejemplo n.º 27
0
 internal void CallOnModelBasicNacks(BasicNackEventArgs args)
 {
     OnModelBasicNacks(null, args);
 }
 /// <summary>
 /// Handles the BasicNacks event of the Channel control.
 /// </summary>
 /// <param name="sender">The source of the event.</param>
 /// <param name="e">The <see cref="BasicNackEventArgs"/> instance containing the event data.</param>
 private void Channel_BasicNacks(object sender, BasicNackEventArgs e)
 {
 }
Ejemplo n.º 29
0
 public virtual void OnBasicNack(BasicNackEventArgs args)
 {
     m_delegate.OnBasicNack(args);
 }
Ejemplo n.º 30
0
 protected virtual void OnModelBasicNacks(Object sender, BasicNackEventArgs args)
 {
 }