Example #1
0
        private void HandleDequeue()
        {
            while (!IsStopping)
            {
                BasicDeliverEventArgs ea = RabbitMq.RabbitMqManager.Dequeue(RabbitMqManager.RabbitMqQueue.InboundStaging, 1, 100).FirstOrDefault();
                if (ea == null)
                {
                    //await Task.Delay(1000);
                    System.Threading.Thread.Sleep(1000);
                    continue;
                }

                MtaQueuedMessage qmsg = Serialisation.Deserialise <MtaQueuedMessage>(ea.Body).Result;
                MtaMessage       msg  = new MtaMessage
                {
                    ID                = qmsg.ID,
                    InternalSendID    = qmsg.InternalSendID,
                    MailFrom          = qmsg.MailFrom,
                    RcptTo            = qmsg.RcptTo,
                    VirtualMTAGroupID = qmsg.VirtualMTAGroupID
                };

                RabbitMqManager.Publish(msg, RabbitMqManager.RabbitMqQueue.Inbound, true, qmsg.RabbitMqPriority).Wait();
                RabbitMqManager.Publish(qmsg, RabbitMqManager.RabbitMqQueue.OutboundWaiting, true, qmsg.RabbitMqPriority).Wait();
                RabbitMqManager.Ack(RabbitMqManager.RabbitMqQueue.InboundStaging, ea.DeliveryTag, false);
            }
        }
        /// <summary>
        /// Enqueue the messages in the collection for relaying.
        /// </summary>
        /// <param name="inboundMessages">Messages to enqueue.</param>
        public static void Enqueue(IList <MtaMessage> inboundMessages)
        {
            Parallel.ForEach(inboundMessages, message => {
                Enqueue(MtaQueuedMessage.CreateNew(message)).Wait();
            });

            RabbitMqManager.Ack(RabbitMqManager.RabbitMqQueue.Inbound, inboundMessages.Max(m => m.RabbitMqDeliveryTag), true);
        }
        private static async Task HandleDequeue()
        {
            if (_StartedThreads >= STAGING_DEQUEUE_THREADS)
            {
                return;
            }

            _StartedThreads++;

            while (true)
            {
                BasicDeliverEventArgs ea = RabbitMq.RabbitMqManager.Dequeue(RabbitMqManager.RabbitMqQueue.InboundStaging, 1, 100).FirstOrDefault();
                if (ea == null)
                {
                    await Task.Delay(1000);

                    continue;
                }

                MtaQueuedMessage qmsg = await Serialisation.Deserialise <MtaQueuedMessage>(ea.Body);

                MtaMessage msg = new MtaMessage
                {
                    ID                = qmsg.ID,
                    InternalSendID    = qmsg.InternalSendID,
                    MailFrom          = qmsg.MailFrom,
                    RcptTo            = qmsg.RcptTo,
                    VirtualMTAGroupID = qmsg.VirtualMTAGroupID
                };

                await RabbitMqManager.Publish(msg, RabbitMqManager.RabbitMqQueue.Inbound, true, (RabbitMqPriority)qmsg.RabbitMqPriority);

                await RabbitMqManager.Publish(qmsg, RabbitMqManager.RabbitMqQueue.OutboundWaiting, true, (RabbitMqPriority)qmsg.RabbitMqPriority);

                RabbitMqManager.Ack(RabbitMqManager.RabbitMqQueue.InboundStaging, ea.DeliveryTag, false);
            }
        }
 /// <summary>
 /// Acknowledge the message as handled.
 /// </summary>
 /// <param name="msg">The message to acknowledge.</param>
 internal static void Ack(MtaQueuedMessage msg)
 {
     RabbitMqManager.Ack(RabbitMqManager.RabbitMqQueue.OutboundWaiting, msg.RabbitMqDeliveryTag, false);
 }