Finally, send a message from the Publisher, and watch it appear on the Subscriber. Then, launch TestPublisher on the Publisher machine. Launch TestSubscriber.exe on the Subscriber machine first. Likewise, copy the contents of TestSubscriber\bin\Debug to a folder on the Subscriber. Copy the contents of TestPublisher\bin\Debug to a folder on the Publisher. Build the sample applications that we created in the previous post. Now, on either the Publisher or the Subscriber, open the web-based management console at (Recall from our previous post that the web-based management console is a plugin we need to install.) On the first page, you will see the details of our newly created, multi-node cluster!
Restart the RabbitMQ Windows service after running this command. > rabbitmqctl join_cluster we are doing here is telling the instance of RabbitMQ running on the Subscriber machine that we want to join a cluster that is hosted by the Publisher machine (which is currently a cluster of one). Run the following commands: > rabbitmqctl stop_app Now, from the Subscriber machine, open up the “RabbitMQ Command Prompt (sbin dir)” item (added by the RabbitMQ installer). If you’ve got the Windows Firewall turned on, be sure to allow incoming TCP traffic on ports 432 on both the Publisher and Subscriber machines. Restart the RabbitMQ service on both machines. All four cookies should have identical content (you can inspect with Notepad to be sure). Copy the cookie from C:\Windows on the Publisher machine to C:\Users\ Current User on the same machine and then to both C:\Users\ Current User and C:\Windows on the Subscriber machine. The RabbitMQ clustering guide recommends making sure all of the cookies on the machine are the same. When installing Erlang on Windows and installing RabbitMQ as a Windows Service, the Erlang cookie is placed in two locations – C:\Users\ Current User and C:\Windows. All the nodes in a RabbitMQ cluster must have the same Erlang cookie. It is a key that indicates that the multiple Erlang nodes can communicate with each other.
The Erlang cookie is a corollary to this process. (Remember, RabbitMQ is an Erlang application.) ASP.NET developers may be familiar with the concept of creating a common Machine Key for a cluster of web servers. The first thing that needs to be done is to set up the Erlang cookie on each machine so that the cookies are the same.
Install RabbitMQ on each of these machines, referring to the installation instructions in my previous blog post. The diagram below illustrates this pattern.įor the purposes of this example, we are going to assume you have two Windows machines (virtual or otherwise) named Publisher and Subscriber.
Then, I will install an instance of RabbitMQ on each machine that will be running a service that will subscribe to the messages. For example, I will install instances of RabbitMQ on each web server that makes up a web application and will be publishing messages related to the application. (Note that queues can be replicated for high-availability requirements, which we may cover in a future post.) A Common Clustering PatternĪ pattern I like to use for clustering RabbitMQ nodes is to have a node live on each machine that participates in the overall application.
The actual queue, or mailbox, only lives on the node where the queue was created, but the knowledge of the queue’s existence is shared by the cluster, as is the full routing information contained in the exchanges. Recall from our last discussion that an exchange is like a post office and a queue is like an actual mailbox containing the resting place of messages. All of the nodes will share configuration information, such as users, exchanges, and queues.
RabbitMQ ClusteringĪ RabbitMQ cluster (or broker) can consist of multiple nodes, each running an instance of the RabbitMQ application. To do that, we need to set up a RabbitMQ cluster. In the real world, your publishers are most likely to live on separate machines from your subscribers. In the example, however, we were only using a single RabbitMQ instance on a single machine.
In my last post, A Simple MassTransit Publish/Subscribe Example, we looked at how to build basic publishers and subscribers using MassTransit and RabbitMQ.