Subscribing to messages
Here is our code for subscribing to our deployment messages. As in previous chapters, we create our connection to RabbitMQ, create our exchange
and queue
, bind them together, and then subscribe to our messages, providing the procedure we will use to process our messages:
public 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("Deployments");
Bus.Advanced.Bind(exchange, queue, "");
Bus.Subscribe<DeploymentStartMessage>("Deployment.Start", msg => { ProcessDeploymentStartMessage(msg); },
config => config.WithTopic("Deployments"));
Bus.Subscribe<DeploymentStopMessage>("Deployment.Stop", msg => { ProcessDeploymentStopMessage(msg); },
config => config.WithTopic("Deployments"));
}