[rabbitmq-discuss] How can I connect in a cluster using Java library

Emile Joubert emile at rabbitmq.com
Wed Mar 16 14:23:17 GMT 2011


Hi Lucas,

On 16/03/11 13:48, Lucas Souza wrote:

> ConnectionFactory factory = new ConnectionFactory();
> Address[] addresses = {new Address("localhost", 12345), new
> Address("localhost", 12346)};
> factory.newConnection(addresses);
>
> If I'll do this, how can I know what node of cluster I'm connected?

It shouldn't matter which node you are connected to (unless you care 
about the locations of queues). Clients see an identical view of the 
world regardless of which broker in the same cluster they connect to.

A channel can query the underlying connection. You can find the address 
of the clustered node that way if necessary.

> If node 1 down, but node 2 still up, how can I reconnect in node 1?

The factory connection does not offer robust reconnection logic. If you 
want clients to reconnect then take a look at the message patterns library:

http://hg.rabbitmq.com/rabbitmq-java-messagepatterns

This is a higher-level library that offers reconnection logic, which is 
sufficiently flexible for use with clusters.


Regards

Emile



More information about the rabbitmq-discuss mailing list