Beispiel #1
0
        /// <summary>
        /// Called when a acknowledge message is received from the client
        /// </summary>
        internal async Task AcknowledgeDelivered(MqClient from, TmqMessage deliveryMessage)
        {
            MessageDelivery delivery = TimeKeeper.FindAndRemoveDelivery(from, deliveryMessage.MessageId);

            //when server and consumer are in pc,
            //sometimes consumer sends ack before server start to follow ack of the message
            //that happens when ack message is arrived in less than 0.01ms
            //in that situation, server can't find the delivery with FindAndRemoveDelivery, it returns null
            //so we need to check it again after a few milliseconds
            if (delivery == null)
            {
                await Task.Delay(1);

                delivery = TimeKeeper.FindAndRemoveDelivery(from, deliveryMessage.MessageId);

                //try again
                if (delivery == null)
                {
                    await Task.Delay(3);

                    delivery = TimeKeeper.FindAndRemoveDelivery(from, deliveryMessage.MessageId);
                }
            }

            bool success = true;

            if (deliveryMessage.Length > 0 && deliveryMessage.Content != null)
            {
                string msg = deliveryMessage.Content.ToString();
                if (msg.Equals("FAILED", StringComparison.InvariantCultureIgnoreCase) || msg.Equals("TIMEOUT", StringComparison.InvariantCultureIgnoreCase))
                {
                    success = false;
                }
            }

            if (delivery != null)
            {
                delivery.MarkAsAcknowledged(success);
            }

            if (success)
            {
                Info.AddAcknowledge();
            }
            else
            {
                Info.AddUnacknowledge();
            }

            Decision decision = await DeliveryHandler.AcknowledgeReceived(this, deliveryMessage, delivery, success);

            if (delivery != null)
            {
                if (Options.HideClientNames)
                {
                    deliveryMessage.SetSource(null);
                }

                await ApplyDecision(decision, delivery.Message, deliveryMessage);
            }

            ReleaseAcknowledgeLock(true);
        }
Beispiel #2
0
        /// <summary>
        /// Called when a acknowledge message is received from the client
        /// </summary>
        internal async Task AcknowledgeDelivered(MqClient from, HorseMessage deliveryMessage)
        {
            try
            {
                if (!IsInitialized)
                {
                    return;
                }

                MessageDelivery delivery = TimeKeeper.FindAndRemoveDelivery(from, deliveryMessage.MessageId);

                //when server and consumer are in pc,
                //sometimes consumer sends ack before server start to follow ack of the message
                //that happens when ack message is arrived in less than 0.01ms
                //in that situation, server can't find the delivery with FindAndRemoveDelivery, it returns null
                //so we need to check it again after a few milliseconds
                if (delivery == null)
                {
                    await Task.Delay(1);

                    delivery = TimeKeeper.FindAndRemoveDelivery(from, deliveryMessage.MessageId);

                    //try again
                    if (delivery == null)
                    {
                        await Task.Delay(3);

                        delivery = TimeKeeper.FindAndRemoveDelivery(from, deliveryMessage.MessageId);
                    }
                }

                bool success = !(deliveryMessage.HasHeader &&
                                 deliveryMessage.Headers.Any(x => x.Key.Equals(HorseHeaders.NEGATIVE_ACKNOWLEDGE_REASON, StringComparison.InvariantCultureIgnoreCase)));

                // ReSharper disable once ConditionIsAlwaysTrueOrFalse (it's possible, resharper doesn't work properly in here)
                if (delivery != null)
                {
                    if (delivery.Receiver != null && delivery.Message == delivery.Receiver.CurrentlyProcessing)
                    {
                        delivery.Receiver.CurrentlyProcessing = null;
                    }

                    delivery.MarkAsAcknowledged(success);
                }

                if (success)
                {
                    Info.AddAcknowledge();
                }
                else
                {
                    Info.AddNegativeAcknowledge();
                }

                Decision decision = await DeliveryHandler.AcknowledgeReceived(this, deliveryMessage, delivery, success);

                // ReSharper disable once ConditionIsAlwaysTrueOrFalse (it's possible, resharper doesn't work properly in here)
                if (delivery != null)
                {
                    if (Options.HideClientNames)
                    {
                        deliveryMessage.SetSource(null);
                    }

                    await ApplyDecision(decision, delivery.Message, deliveryMessage);
                }

                ReleaseAcknowledgeLock(true);
            }
            catch (Exception e)
            {
                Server.SendError("QUEUE_ACK_RECEIVED", e, $"QueueName:{Name}, MessageId:{deliveryMessage.MessageId}");
            }
        }