/// <summary> /// Enqueue the message for relaying. /// </summary> /// <param name="msg">Message to enqueue.</param> public static async Task <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; } } var published = await RabbitMqManager.Publish(msg, queue, priority : msg.RabbitMqPriority); if (published) { msg.IsHandled = true; } return(published); }
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> /// 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> /// <param name="priority">Priority of message.</param> /// <returns>True if the Email has been enqueued in RabbitMQ.</returns> public static async Task <bool> Enqueue(Guid messageID, int ipGroupID, int internalSendID, string mailFrom, string[] rcptTo, string message, RabbitMqPriority priority) { // Create the thing we are going to queue in RabbitMQ. var recordToSave = new MtaMessage { ID = messageID, InternalSendID = internalSendID, MailFrom = mailFrom, Message = message, RcptTo = rcptTo, VirtualMTAGroupID = ipGroupID, RabbitMqPriority = priority }; return(await RabbitMqManager.Publish(MtaQueuedMessage.CreateNew(recordToSave), RabbitMqManager.RabbitMqQueue.InboundStaging, true, priority)); }
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); } }