Subscribing to email requests

Here's our code that we use to subscribe to our EmailSendRequest messages. Once we receive one we will immediately process this via the ProcessEmailSendRequestMessage function:

public void Subscribe()
{
Bus = RabbitHutch.CreateBus("host=localhost",
x => x.Register<IConventions, AttributeBasedConventions>());
IExchange exchange = Bus.Advanced.ExchangeDeclare("EvolvedAI", ExchangeType.Topic);
IQueue queue = Bus.Advanced.QueueDeclare("Email");
Bus.Advanced.Bind(exchange, queue, Environment.MachineName);
Bus.Subscribe<EmailSendRequest>(Environment.MachineName, msg => { ProcessEmailSendRequestMessage(msg); },
config => config?.WithTopic("Email"))
}

This in turn, calls our internal SendEmail function, passes the message with all the required parameters, and then sends the message:

bool ProcessEmailSendRequestMessage(EmailSendRequest msg)
{
Console.WriteLine("Received Email Send Request Message");
RILogManager.Default?.SendInformation("Received Email Send Request Message");
SendEmail(msg);
return true;
}

Did you notice that when we subscribe to a message this time, we are specifically looking for an exact topic, in this case, EmailWithTopic extensions will be a great help moving forward in subscribing to our intended messages.

Once this is complete, our message will have been sent and received.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset