/// <summary> /// This method listens for email messages on the message queue and sends an email if it receives a message /// </summary> public void Consume() { _channel.ExchangeDeclare(RabbitMqExchange.MailExchange, ExchangeType.Direct); _channel.QueueDeclare(RabbitMqQueues.MailQueue, true, false, false, null); _channel.QueueBind(RabbitMqQueues.MailQueue, RabbitMqExchange.MailExchange, RabbitMqRouting.SendMail); _channel.BasicQos(0, 10, false); var consumer = new EventingBasicConsumer(_channel); consumer.Received += (sender, e) => { try { byte[] body = e.Body.ToArray(); string json = Encoding.UTF8.GetString(body); var emails = Newtonsoft.Json.JsonConvert.DeserializeObject <List <Email> >(json); _emailLogic.SendMails(emails); } catch (Exception exception) { _logLogic.Log(exception); } }; _channel.BasicConsume(RabbitMqQueues.MailQueue, true, consumer); }
public void SendMailsArgumentNullExceptionTest() { Assert.Throws <ArgumentNullException>(() => _emailLogic.SendMails(null)); Assert.Throws <ArgumentNullException>(() => _emailLogic.SendMails(new List <Email>())); }