[rabbitmq-discuss] RMQ Erlang Client: Auto reconnections

Tim Watson tim at rabbitmq.com
Tue Mar 12 09:29:38 GMT 2013

Hi Alex,

On 12 Mar 2013, at 07:05, Alex Hudich wrote:
> ... I can't afford to crash the entire application because of rmq disconnects because it perform a lot of tasks beside rmq messages handling.

That's quite understandable. In the title of the post you've said 'RMQ Erlang Client' so I'm a little confused. If you have an Erlang 'process' that fails, it will not 'crash the entire application' - only if the top level supervisor fails and the application restart_type is permanent will the whole Erlang node stop. So why is your top level supervisor failing, and if you've made connectivity a pre-requisite for starting a process that sits directly beneath the top level supervisor then this is going to continue to happen. After all, if the network is down and the process keeps trying to restart and failing because it cannot establish a connection, what should we expect to happen? You need to decide how your application will cope with this, and more likely than not write some code to deal with it.

Going back to your previous point...

> ... I wonder if there any way to handle disconnects and automatically reconnect process to rmq server. 

The canonical approach to noticing disconnection is to enable heartbeats, ensuring timely discovery of network disruptions. This will terminate your gen_connection process if the heartbeat request times out. As for automatic disconnection, regardless of why a gen_connection (or other) process dies, what's wrong with having one of your supervisors restart the relevant process in order to re-establish connectivity? As I mentioned earlier, it might be useful to use a timer to periodically try to re-connect in case you want to prevent network disruption from bringing your application down, since successive restarts by the supervisor will eventually reach max intensity and cause the supervisor to shut down.


More information about the rabbitmq-discuss mailing list