Subscribing to messages
In order to receive messages we have to subscribe to them. Similar to what we have done in earlier chapters of the book, here we are subscribing to our Speech
queue on the EvolvedAI
exchange. We will be looking for any messages with the topic of Speech
:
private void Subscribe()
{
Bus = RabbitHutch.CreateBus("host=localhost",
x =>
{
x.Register<IConventions, AttributeBasedConventions>();
x.EnableMessageVersioning();
});
IExchange exchange = Bus?.Advanced?.ExchangeDeclare("EvolvedAI", ExchangeType.Topic);
IQueue queue = Bus?.Advanced?.QueueDeclare("Speech");
Bus?.Advanced?.Bind(exchange, queue, "");
Bus?.Subscribe<SpeechRequestMessage>(Environment.MachineName, msg => ProcessSpeechRequestMessage(msg),
config => config?.WithTopic("Speech"));
Bus?.Subscribe<WikipediaSearchMessage>(Environment.MachineName, msg => ProcessWikipediaSearchMessage(msg),
config => config?.WithTopic("Speech"));
}