Now that we have covered a lot of the introductory material for RabbitMQ, this part of the series will look at developing software to interact with the message broker as both a producer and a consumer. First we will take a look at the RabbitMQ client library. Then we will introduce the business scenario used for the sample applications. Before we start looking at the individual examples we will take a quick look at the common code shared between them. Then we will move onto the actual code examples themselves.
To develop software against RabbitMQ you will need to install the RabbitMQ client library for .NET. Before we look at how to install the client library, let’s take a brief look at what it is. This series will not serve as an in-depth guide to the whole client library API. You can read a more in-depth document for the client library that explains the full library from the RabbitMQ site. This section will serve as an introduction to the library and the examples in the rest of this series will help you cement your understanding further.
What is contained in the Client Library?
The RabbitMQ .NET client is an implementation of an AMQP client library for C# and other .NET languages. The client library implements the AMQP specification 0-8 and 0-9. The API is closely modeled on the AMQP protocol specification with little additional abstraction, so if you have a good understanding of the AMQP protocol, then you will find the client library easy to follow.
The core API interfaces and classes are defined in the RabbitMQ.Client namespace. The main API interfaces and classes are:
IModel : This represents an AMQP data channel and provides most of the AMQP operations.
As a band owner myself, I have been wanting to get involved with developing against this device to read sensor data now that I have started down the Universal Windows App road, and this talk give you a good introduction so that you can get started right away.
I highly recommend watching it.
You can get started on your Microsoft Band Development journey by going to the official developer site.
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.
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.
In the previous article we looked the Rabbit MQ management portal in more detail. In this article we will look at configuring RabbitMQ from the command line.
As well as using the web based management portal to administer RabbitMQ you can also use the command line (rabbitmqctrl.bat) interface. In this chapter we will demonstrate some of the basic features that you may need to use most frequently, but for a more exhaustive list of commands you can read the RabbitMQ manual page for the rabbitmqctrl.bat tool.
At a high level rabbitmqctrl lets you manage the run state of the message broker, manage your RabbitMQ clusters, administer users and permissions, manage policies and list exchanges, bindings, and queues.
Let’s work through a simple example of stopping and starting the RabbitMQ broker and checking the broker status.
Open up a command prompt and navigate to “C:\Program Files (x86)\RabbitMQ Server\rabbitmq_server-3.4.4\sbin
From the command prompt type:
You will see the following output in the command line window.
To stop the RabbitMQ broker from running you type the following into the command line:
This will give you console output that looks as following:
If you run the status command line again by typing:
You will see that the RabbitMQ service has stopped. This will mean RabbitMQ will stop receiving and processing messages. If you have not setup durable queues and messages you will lose any messages already in the system.
I am pleased to announce that I am now the Co-Organiser of the Derbyshire DotNet usergroup here in Derby, United Kingdom. The usergroup was set-up by Barry Mills and I have joined forces with Barry to assist in the running of the User Group.
This is the user groups first year in existence, and I even did a talk back in March on Cryptography in .NET.
The official description for the group is :
Derbyshire Dot Net is a monthly .Net User Group meeting for those who are passionate about .Net Development in the Derbyshire area.
It was born out of a frustration that there were no groups in Derbyshire that were formally supported by Microsoft or INETA. Derbyshire Dot Net exists to help facilitate education and knowledge exchange among developers, architects and managers with an interest in Microsoft’s .NET technologies. We provide a great place for local developers to come together to learn all about .NET technologies, to network with their peers and to foster a sense of community among developers learning and using the same technologies.
Our vision is to share knowledge with the technical community of Derbyshire and to encourage developers to grow their careers and step out of their comfort zone to give talks and presentations of their own.
My first task has been setting up a new website / blog for the usergroup which I have done and can be found at www.derbyshiredotnet.co.uk. We want to turn this into a proper community website as opposed to just being a notice board.
The user group holds its meeting on the 3rd Thursday of the month and our venue has kindly been donated by Xpertise Recruitment in Derby.
So, if you are around the area, then please do come along and join one of our sessions. Also, if you want to speak at our usergroup, then please get in touch.
The management portal is split into different screens that are selectable with the menu bar at the top of the screen. The first screen you will see is the overview page. This acts as a dashboard view showing you how many messages are in the broker, and the message throughput rate.
This screen is useful to have up on a large display so you can see at a glance how RabbitMQ is performing. If, for example, any of your message consumer applications go down, you will start to see a large buildup of undelivered messages which is a good indication that something has gone wrong.
In the image above, you can see on the overview screen that 1 messages was placed onto the queue at 10:49.00. In the chart below this you can see the message rates which is split into Published messages, Delivered messages, Redelivered messages, Acknowledged messages and Delivered messages where no acknowledgement was required.
In the previous article we look at the AMQP messaging standard that sits behind RabbitMQ. In this article we will look at installing and configuring RabbitMQ.
Now that we have covered the basics of message queuing, RabbitMQ, and the AMQP model, let’s get RabbitMQ installed and configured. When you set up RabbitMQ on a server, you need to install two components. First, you need the Erlang run time and then RabbitMQ itself. First, go to the RabbitMQ website to download it.
Once you are on this page, select “Install: Windows” from the grey panel to the right of the screen:
From this page, click the link to the “Erlang Windows Binary File” as shown in the following screen shot. This will take you to the Erlang website downloads page.
When you are on the Erlang site, pick the latest version of the runtime that matches your operating system. If you are running a 64bit operating system, then pick the 64bit version and visa versa with the 32bit version.