2015-09-23

In the previous article we looked at administering RabbitMQ from the command line. In this next article we will set-up a basic queue and also send and receive a basic message via the management portal.

Before we go and dive into some code and look at our samples, let’s work through a very simple scenario where we create an exchange and a queue and bind them together via the management portal. We will then send a message to the exchange and pull it from the queue. It is a very simple example, but it serves as a good introduction before we tackle some real world scenarios.

First of all go to the management portal and click on the exchanges tab. Once you are on the exchanges page, open up the ‘Add a new exchange’ section and fill it in as shown in the following screenshot. You will then need to click on the “Add exchange” button to add the exchange.



RabbitMQ Basic Queue and Message Example

This will add a new ‘direct’ exchange to the list of exchanges. Now click on the Queues tab at the top of the page to go to the queue list. Open up the ‘Add a new queue’ section and fill it in as per the following screenshot. Now click the “Add queue” button.



RabbitMQ Basic Queue and Message Example

You will see this TestQueue appear in the queues list. Now, click on the TestQueue in that list. This will take you to the page for that queue specifically.  If you scroll down to the bindings section and open it, you will see, as per the following screenshot, that this queue is not bound any exchanges.



RabbitMQ Basic Queue and Message Example

To bind the queue to our TestExchange, type the name of the exchange into the ‘From exchange’ text box and then hit the ‘Bind’ button. We will not put in a routing key for this example. You will now notice that this queue is bound to the TestExchange exchange.

RabbitMQ Basic Queue and Message Example

Now, go back to the exchanges tab in the management portal and scroll down to the ‘Publish message’ section further down the page. This is in a collapsible section so you may need to open it up. You should see the publish message options as in the screenshot below.

We are not using a routing key in this example, so leave that blank. In the payload section, write a message. In the screen shot we are using our traditional Hello World sample.

RabbitMQ Basic Queue and Message Example

Now go back to the ‘Queues’ tab and select our TestQueue. You will notice that the chart is showing 1 queued message.

RabbitMQ Basic Queue and Message Example

Scroll down to the bottom of that screen and open up the ‘Get messages’ section.

RabbitMQ Basic Queue and Message Example

If you click the ‘Get Message(s)’ button you will now see how the message payload has now been removed from the queue.

RabbitMQ Basic Queue and Message Example

If you look at the message chart at the top of the page, you will see that there is still a message in the queue. This is because when we got the message, the ‘Requeue’ parameter was set to ‘Yes’. This means that once we have extracted the message, it was replaced back on the queue.

This time, set the ‘Requeue’ parameter to ‘No’ and get the message again. You will see the same message come back, but if you scroll back to the queues messages chart at the top of the screen you will see that the message has gone and there are no messages left in the queue.

RabbitMQ Basic Queue and Message Example

Although this is a very simple example, you should now be at a point where you have a good understanding of what RabbitMQ is about, how to install and configure it, and how the basic process of setting up and binding exchanges and queues works. We are now ready to start looking at some real code.

In the next article we will start to look at some examples using the client library. We will first look at how to install the client library and then walk through some boiler plate code before pressing on with the first example.

Show more