Exemple #1
0
        /// <summary>
        /// Enqueue the message for relaying.
        /// </summary>
        /// <param name="msg">Message to enqueue.</param>
        public static bool Enqueue(MtaQueuedMessage msg)
        {
            RabbitMqManager.RabbitMqQueue queue = RabbitMqManager.RabbitMqQueue.OutboundWaiting;

            int secondsUntilNextAttempt = (int)Math.Ceiling((msg.AttemptSendAfterUtc - DateTime.UtcNow).TotalSeconds);

            if (secondsUntilNextAttempt > 0)
            {
                if (secondsUntilNextAttempt < 10)
                {
                    queue = RabbitMqManager.RabbitMqQueue.OutboundWait1;
                }
                else if (secondsUntilNextAttempt < 60)
                {
                    queue = RabbitMqManager.RabbitMqQueue.OutboundWait10;
                }
                else if (secondsUntilNextAttempt < 300)
                {
                    queue = RabbitMqManager.RabbitMqQueue.OutboundWait60;
                }
                else
                {
                    queue = RabbitMqManager.RabbitMqQueue.OutboundWait300;
                }
            }

            if (!RabbitMqManager.Publish(msg, queue))
            {
                return(false);
            }
            msg.IsHandled = true;
            return(true);
        }
Exemple #2
0
        private static void HandleDequeue()
        {
            if (_StartedThreads >= STAGING_DEQUEUE_THREADS)
            {
                return;
            }

            _StartedThreads++;

            while (true)
            {
                BasicDeliverEventArgs ea = RabbitMq.RabbitMqManager.Dequeue(RabbitMqManager.RabbitMqQueue.InboundStaging, 1, 100).FirstOrDefault();
                if (ea == null)
                {
                    Thread.Sleep(1000);
                    continue;
                }

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

                RabbitMqManager.Publish(msg, RabbitMqManager.RabbitMqQueue.Inbound, true);
                RabbitMqManager.Publish(qmsg, RabbitMqManager.RabbitMqQueue.OutboundWaiting, true);
                RabbitMqManager.Ack(RabbitMqManager.RabbitMqQueue.InboundStaging, ea.DeliveryTag, false);
            }
        }
Exemple #3
0
        /// <summary>
        /// Enqueues the Email that we are going to relay in RabbitMQ.
        /// </summary>
        /// <param name="messageID">ID of the Message being Queued.</param>
        /// <param name="ipGroupID">ID of the Virtual MTA Group to send the Message through.</param>
        /// <param name="internalSendID">ID of the Send the Message is apart of.</param>
        /// <param name="mailFrom">The envelope mailfrom, should be return-path in most instances.</param>
        /// <param name="rcptTo">The envelope rcpt to.</param>
        /// <param name="message">The Email.</param>
        /// <returns>True if the Email has been enqueued in RabbitMQ.</returns>
        public static bool Enqueue(Guid messageID, int ipGroupID, int internalSendID, string mailFrom, string[] rcptTo, string message)
        {
            // Create the thing we are going to queue in RabbitMQ.
            MtaMessage recordToSave = new MtaMessage(messageID,
                                                     ipGroupID,
                                                     internalSendID,
                                                     mailFrom,
                                                     rcptTo,
                                                     message);

            return(RabbitMqManager.Publish(MtaQueuedMessage.CreateNew(recordToSave), RabbitMqManager.RabbitMqQueue.InboundStaging, true));
        }