Example #1
0
        public void SuccessfulPublish(IModel channel, BasicAckEventArgs args)
        {
            if (args == null)
            {
                throw new ArgumentNullException("args");
            }

            ProcessArgsAndRun(args.Multiple, args.DeliveryTag, x => x.Success());
        }
        public void Should_mark_success()
        {
            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 BasicAckEventArgs
            {
                DeliveryTag = sequenceNumber,
                Multiple = false
            };

            publisherConfirms.SuccessfulPublish(channel, args);

            success.ShouldBeTrue();
            failure.ShouldBeFalse();
        }
Example #3
0
        private void OutboundModelOnBasicAcks(IModel model, BasicAckEventArgs args)
        {
            ulong tag;

            if(toBeConfirmed.TryRemove(args.DeliveryTag, out tag))
                inboundModel.BasicAck(tag, false);
        }
		private void OnChannelAck(
			IModel channel,
			BasicAckEventArgs 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);
			}
		}
 public void HandleBasicAck(ulong deliveryTag,
                            bool multiple)
 {
     BasicAckEventArgs e = new BasicAckEventArgs();
     e.DeliveryTag = deliveryTag;
     e.Multiple = multiple;
     OnBasicAck(e);
 }
 void OnBasicAcks(object model, BasicAckEventArgs args)
 {
     if (args.Multiple)
     {
         ulong[] ids = _published.Keys.Where(x => x <= args.DeliveryTag).ToArray();
         foreach (var id in ids)
         {
             PendingPublish value;
             if (_published.TryRemove(id, out value))
                 value.Ack();
         }
     }
     else
     {
         PendingPublish value;
         if (_published.TryRemove(args.DeliveryTag, out value))
             value.Ack();
     }
 }
 public void HandleBasicAck(ulong deliveryTag,
     bool multiple)
 {
     var e = new BasicAckEventArgs
     {
         DeliveryTag = deliveryTag,
         Multiple = multiple
     };
     OnBasicAck(e);
 }
        public void SuccessfulPublish(IModel channel, BasicAckEventArgs args)
        {
            Preconditions.CheckNotNull(args, "args");

            ProcessArgsAndRun(args.Multiple, args.DeliveryTag, x => x.Success());
        }
 protected override void OnBrokerReceivedMessage(IModel model, BasicAckEventArgs args)
 {
     OnBrokerReceivedMessageIsCall = true;
 }
 private void ModelOnBasicAcks(IModel model, BasicAckEventArgs args)
 {
     MarkAsConfirmed(args.DeliveryTag, args.Multiple);
 }
Example #11
0
 private void ModelOnBasicAcks(object sender, BasicAckEventArgs e)
 {
     _logger.Debug($"Ack, tag: {e.DeliveryTag}, multiple: {e.Multiple}");
     Ack?.Invoke(this, e);
 }
Example #12
0
 private void OnAck(object sender, BasicAckEventArgs args)
 {
     eventBus.Publish(MessageConfirmationEvent.Ack((IModel) sender, args.DeliveryTag, args.Multiple));
 }
 protected override void OnBrokerReceivedMessage(object sender, BasicAckEventArgs args)
 {
     OnBrokerReceivedMessageIsCall = true;
 }
		private void OnChannelAck(
			IModel channel,
			BasicAckEventArgs args)
		{
			this.c_writeLog(string.Format("On channel ack : Is multiple {0}, delivery tag {1}", args.Multiple, args.DeliveryTag));
			var _confirmedDeliveryTags = this.c_unconfirmedMessages.Keys.Where(deliveryTag => deliveryTag <= args.DeliveryTag);  // Linq perf here ?
			var _removedMessage = string.Empty;
			foreach (var _confirmedDeliveryTag in _confirmedDeliveryTags)
			{
				if (!this.c_unconfirmedMessages.TryRemove(_confirmedDeliveryTag, out _removedMessage))
				{
					throw new ApplicationException("Could not remove delivery tag entry");
				}
			}
		}
Example #15
0
 private void ModelOnBasicAcks(object model, BasicAckEventArgs e)
 {
     HandleConfirm(e.DeliveryTag, e.Multiple, x => x.OnAck());
 }
Example #16
0
        private void PublishModelOnBasicAcks(IModel model, BasicAckEventArgs args)
        {
            IUnconfirmedDeliveryFactory _;

            if (args.Multiple)
            {
                log.DebugFormat("Broker confirmed all deliveries up to and including #{0}", args.DeliveryTag);

                var toRemove = unconfirmedCommands.Keys.Where(tag => tag <= args.DeliveryTag).ToArray();

                foreach (var tag in toRemove)
                    unconfirmedCommands.TryRemove(tag, out _);
            }
            else
            {
                log.DebugFormat("Broker confirmed delivery #{0}", args.DeliveryTag);
                unconfirmedCommands.TryRemove(args.DeliveryTag, out _);
            }

            log.DebugFormat("Left to be confirmed: {0}", unconfirmedCommands.Count);
        }
Example #17
0
 private void ConfirmChannel_BasicAcks(object sender, BasicAckEventArgs args)
 {
     string fileName;
     lock (_ConfirmMessagesWaitingAck)
     {
         if (args.Multiple)
         {
             for (ulong index = args.DeliveryTag; index > 0; index--)
             {
                 if (_ConfirmMessagesWaitingAck.TryGetValue(index, out fileName))
                 {
                     _ConfirmMessagesWaitingAck.Remove(index);
                     DeleteMessageFile(fileName);
                 }
                 else
                 {
                     break;
                 }
             }
             _LastConfirmSeqNo = args.DeliveryTag + 1;
         }
         else
         {
             if (_ConfirmMessagesWaitingAck.TryGetValue(args.DeliveryTag, out fileName))
             {
                 _ConfirmMessagesWaitingAck.Remove(args.DeliveryTag);
                 DeleteMessageFile(fileName);
             }
             if (_LastConfirmSeqNo == args.DeliveryTag)
                 _LastConfirmSeqNo = args.DeliveryTag + 1;
         }
     }
 }
Example #18
0
        protected override void OnModelBasicAcks(Object sender, BasicAckEventArgs args)
        {
            base.OnModelBasicAcks(sender, args);

            _log.Info($"consumer-model basic.ack received (delivery-tag: {args.DeliveryTag}, multiple: {args.Multiple})");
        }
Example #19
0
 private void ModelOnBasicAcks(IModel model, BasicAckEventArgs args)
 {
     HandleConfirm(args.DeliveryTag, args.Multiple, x => x.OnAck());
 }
Example #20
0
 protected virtual void OnModelBasicAcks(Object sender, BasicAckEventArgs args) { }
        public virtual void OnBasicAck(BasicAckEventArgs args)
        {
            EventHandler<BasicAckEventArgs> handler;
            lock (m_eventLock)
            {
                handler = m_basicAck;
            }
            if (handler != null)
            {
                foreach (EventHandler<BasicAckEventArgs> h in handler.GetInvocationList())
                {
                    try
                    {
                        h(this, args);
                    }
                    catch (Exception e)
                    {
                        OnCallbackException(CallbackExceptionEventArgs.Build(e, "OnBasicAck"));
                    }
                }
            }

            handleAckNack(args.DeliveryTag, args.Multiple, false);
        }
Example #22
0
 private void BasicAckEventHandler(object sender, BasicAckEventArgs e)
 {
     this.BasicAcks?.Invoke(sender, e);
 }
 public virtual void OnBasicAck(BasicAckEventArgs args)
 {
     m_delegate.OnBasicAck(args);
 }
		private void OnChannelAck(
			IModel channel,
			BasicAckEventArgs args)
		{
			var _removedMessage = string.Empty;
			var _confirmedDeliveryTags = this.c_unconfirmedMessages.Keys.Where(deliveryTag => deliveryTag <= args.DeliveryTag);
			foreach (var _confirmedDeliveryTag in _confirmedDeliveryTags)
			{
				if (!this.c_unconfirmedMessages.TryRemove(_confirmedDeliveryTag, out _removedMessage))
				{
					throw new ApplicationException("Could not remove delivery tag entry");
				}
			}
		}
        public virtual void OnBasicAck(BasicAckEventArgs args)
        {
            BasicAckEventHandler handler;
            lock (m_eventLock)
            {
                handler = m_basicAck;
            }
            if (handler != null)
            {
                foreach (BasicAckEventHandler h in handler.GetInvocationList()) {
                    try {
                        h(this, args);
                    } catch (Exception e) {
                        CallbackExceptionEventArgs exnArgs = new CallbackExceptionEventArgs(e);
                        exnArgs.Detail["context"] = "OnBasicAck";
                        OnCallbackException(exnArgs);
                    }
                }
            }

            handleAckNack(args.DeliveryTag, args.Multiple, false);
        }
Example #26
0
		private void OnChannelAcked(
			IModel channel,
			BasicAckEventArgs args)
		{
			this.c_logger.DebugFormat("OnChannelAcked Starting, is multiple = {0} and delivery tag = {1}", args.Multiple, args.DeliveryTag);

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

			this.c_logger.DebugFormat("OnChannelAcked Completed, is multiple = {0} and delivery tag = {1}", args.Multiple, args.DeliveryTag);
		}
 /// <summary>
 /// CONFIRM mode
 /// Used to ack publisher confirm
 /// </summary>
 /// <param name="model"></param>
 /// <param name="args"></param>
 protected virtual void Channel_BasicAcks( IModel model, BasicAckEventArgs args )
 {
     //Once a channel is in confirm mode, both the broker and the client count messages (counting starts at 1 on the first confirm.select).
     //The broker then confirms messages as it handles them by sending a basic.ack on the same channel. The delivery-tag field contains the sequence number of the confirmed message.
     //The broker may also set the multiple field in basic.ack to indicate that all messages up to and including the one with the sequence number have been handled.
     //SUPPORT multi!
     TaskCompletionSource<int> tcs;
     if (this.ConfirmTaskCompletions.TryRemove ( args.DeliveryTag, out tcs ))
     {
         //standarize on error codes what does it mean to return 0???
         tcs.SetResult ( 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);
        }