Connecting to multiple rabbitmq hosts

1,922 views
Skip to first unread message

Tushar Pokle

unread,
May 19, 2014, 9:40:34 PM5/19/14
to clojure-...@googlegroups.com
Hi there,

I'd like to connect to multiple RabbitMQ servers for high availability. I can't find a way to do this with Langohr. 

The Java RabbitMQ API has a way of doing this, but I can't find a way to do it with Langohr. 

ConnectionFactory factory = new ConnectionFactory();

Address[] addresses = {new Address("192.168.1.4"), new Address("192.168.1.5")};
factory.newConnection(addresses);

Michael Klishin

unread,
May 19, 2014, 10:06:51 PM5/19/14
to Tushar Pokle, clojure-...@googlegroups.com
On 20 May 2014 at 05:40:35, Tushar Pokle (tushar...@gmail.com) wrote:
> > I'd like to connect to multiple RabbitMQ servers for high availability. 

Note that the API you're mentioning *does not* connect to multiple nodes at once.
It simply connects to the first node reachable (and, in the Java client, picks
a random node when trying to reconnect). You can achieve the same by using
a proxy in front of your cluster. 

> I can't find a way to do this with Langohr.
>
> The Java RabbitMQ API has a way of doing this, but I can't find a
> way to do it with Langohr.

There once was a way to do this — langohr.core/create-address-array hints at this —
but that feature seems to got lost when we added automatic connection recovery.

It should be straightforward to add back.
--
MK

Software Engineer, Pivotal/RabbitMQ

Michael Klishin

unread,
May 19, 2014, 10:41:46 PM5/19/14
to Tushar Pokle, clojure-...@googlegroups.com
 On 20 May 2014 at 06:07:22, Michael Klishin (mkli...@gopivotal.com) wrote:
> > It should be straightforward to add back.

Filed a bug:
https://github.com/michaelklishin/langohr/issues/51

Michael Klishin

unread,
May 20, 2014, 5:49:51 AM5/20/14
to Tushar Pokle, clojure-...@googlegroups.com
 On 20 May 2014 at 06:42:16, Michael Klishin (mkli...@gopivotal.com) wrote:
> > Filed a bug:
> https://github.com/michaelklishin/langohr/issues/51

Fixed in master:

https://github.com/michaelklishin/langohr/compare/a21efaa...f7988997bf

Tushar Pokle

unread,
May 20, 2014, 8:36:13 AM5/20/14
to clojure-...@googlegroups.com
Thanks Michael. I wanted to fail over to any node from a list of nodes, so that's perfect.

Tushar Pokle

unread,
May 21, 2014, 1:43:41 AM5/21/14
to clojure-...@googlegroups.com, Tushar Pokle
I've tested master now, and I think I've found an issue. 

If you specify connect settings with just :hosts, and no :host, then automatic recovery tries to recover using localhost rather than one of the hosts you've specified.

The workaround is to specify :host as well as :hosts - but I don't think that's what you intended.

Cheers,
Tushar

Michael Klishin

unread,
May 21, 2014, 1:45:43 AM5/21/14
to Tushar Pokle, clojure-...@googlegroups.com
 On 21 May 2014 at 09:43:42, Tushar Pokle (tushar...@gmail.com) wrote:
> > If you specify connect settings with just :hosts, and no :host,
> then automatic recovery tries to recover using localhost rather
> than one of the hosts you've specified.
>
> The workaround is to specify :host as well as :hosts - but I don't
> think that's what you intended.

Correct. Will take a look soon.

Michael Klishin

unread,
May 21, 2014, 1:55:12 AM5/21/14
to Tushar Pokle, clojure-...@googlegroups.com
On 21 May 2014 at 09:43:42, Tushar Pokle (tushar...@gmail.com) wrote:
> > I've tested master now, and I think I've found an issue.
>
> If you specify connect settings with just :hosts, and no :host,
> then automatic recovery tries to recover using localhost rather
> than one of the hosts you've specified.
>
> The workaround is to specify :host as well as :hosts - but I don't
> think that's what you intended.

Should be OK now:
https://github.com/michaelklishin/langohr/commit/50f902ec2209fdfcc5b8c6c3da2d160d2f2a3f1f

Tushar Pokle

unread,
May 22, 2014, 3:14:11 AM5/22/14
to Michael Klishin, clojure-...@googlegroups.com
Awesome. I've tested it, and langohr fails over correctly to all hosts in the list now. Thanks for your help!
Reply all
Reply to author
Forward
0 new messages