O'Reilly logo

RabbitMQ Cookbook by Sigismondo Boschi, Gabriele Santomaggio

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Creating clients of the cluster

When you create a simple cluster, the clients may need to specify more than one broker address when connecting. In this recipe, we are going to see how to use the multiple address connections with the RabbitMQ Java client.

Note that in case you have a load balancer in front of the cluster, as shown in the previous recipe, you don't need to use multiple address connections. The load balancer performs this work for you.

Getting ready

You need Java 1.6 or higher and Apache Maven.

How to do it…

Firstly, you need a simple cluster as seen in the Creating a simple cluster recipe.

Then you can connect your client using the following code:

Address[] addrArr = new Address[]{ new Address("node01",portnode1), new Address("node02", ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required