Dynamically creating an exchange

Now that our microservice is reclaiming our memory as we intended, we need to stop and make sure that we have a basic understanding of how our communication mechanism between microservices is going to work. In order to connect and publish our message, we needed to dynamically ensure that both our exchange and queue have been created. We do this in our Subscribe method, as shown in the following code snippet:

public static void Subscribe()
{
Bus = RabbitHutch.CreateBus("host=localhost",
x => x.Register<IConventions, AttributeBasedConventions>());

Declare the exchange:

IExchange exchange = Bus.Advanced.ExchangeDeclare("EvolvedAI", ExchangeType.Topic);

Declare the queue:

IQueue queue = Bus.Advanced.QueueDeclare("Memory");

Bind the queue to the exchange for message delivery using the Bind function:

Bus.Advanced.Bind(exchange, queue, "");
}

With the previous code executed step by step, you can see that the exchange has now been created:

At this point, there is still no queue associated with the exchange for messages to flow through.

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

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