[rabbitmq-discuss] Need clarification on RabbitMq Connection

Michael Klishin mklishin at gopivotal.com
Tue May 13 14:52:16 BST 2014


On 1 May 2014 at 10:24:19, Loganathan Sellapa (loganathan.ms at gmail.com) wrote:
> > This library needs to
>  
> run always and should not close the connection at all, hence it  
> needs to listen & publish messages always, also this library  
> is running to of ROR application.
>  
> For this requirement I have build an rake task to start listening  
> to RabbitMQ, also I have placed the same code in initializers  
> file in order to start the library along with Apache server in  
> production mode. In production mode initializer file is starting  
> my library to listen & publish the messages to RabbitMq. I have  
> noticed that connectiong to RabbitMq behaves differently via  
> rake task & initilazer file, copied below the rabbitmq log for  
> your reference.
>  
> RABBITMQ LOG WHILE RUNNING THE RUBY LIBRARY VIA RAKE TASK: (Connection  
> made one time only)
>  
>  
> =INFO REPORT==== 30-Apr-2014(http://airmail.calendar/2014-04-30%2012:00:00%20GMT+4)::20:43:24  
> ===
> accepting AMQP connection <0.7409.18> (10.146.14.118:54932(http://10.146.14.118:54932/)  
> -> 10.112.187.58:5671(http://10.112.187.58:5671/))
>  
> RABBITMQ LOG WHILE RUNNING THE RUBY LIBRARY VIA INITIALIZER  
> FILE:(Connection made multiple times)
>  
> =INFO REPORT==== 30-Apr-2014(http://airmail.calendar/2014-04-30%2012:00:00%20GMT+4)::20:28:35  
> ===
> accepting AMQP connection <0.6325.18> (10.146.14.118:54928(http://10.146.14.118:54928/)  
> -> 10.112.187.58:5671(http://10.112.187.58:5671/))
>  
> =INFO REPORT==== 30-Apr-2014(http://airmail.calendar/2014-04-30%2012:00:00%20GMT+4)::20:28:35  
> ===
> accepting AMQP connection <0.6329.18> (10.146.14.118:54929(http://10.146.14.118:54929/)  
> -> 10.112.187.58:5671(http://10.112.187.58:5671/))
>  
>  
> =WARNING REPORT==== 30-Apr-2014(http://airmail.calendar/2014-04-30%2012:00:00%20GMT+4)::20:28:37  
> ===
> closing AMQP connection <0.6325.18> (10.146.14.118:54928(http://10.146.14.118:54928/)  
> -> 10.112.187.58:5671(http://10.112.187.58:5671/)):
> connection_closed_abruptly
>  
> =INFO REPORT==== 30-Apr-2014(http://airmail.calendar/2014-04-30%2012:00:00%20GMT+4)::20:28:37  
> ===
> accepting AMQP connection <0.6368.18> (10.146.14.118:54930(http://10.146.14.118:54930/)  
> -> 10.112.187.58:5671(http://10.112.187.58:5671/))
>  
> =WARNING REPORT==== 30-Apr-2014(http://airmail.calendar/2014-04-30%2012:00:00%20GMT+4)::20:28:37  
> ===
> closing AMQP connection <0.6329.18> (10.146.14.118:54929(http://10.146.14.118:54929/)  
> -> 10.112.187.58:5671(http://10.112.187.58:5671/)):
> connection_closed_abruptly
>  
> =INFO REPORT==== 30-Apr-2014(http://airmail.calendar/2014-04-30%2012:00:00%20GMT+4)::20:28:37  
> ===
> accepting AMQP connection <0.6373.18> (10.146.14.118:54931(http://10.146.14.118:54931/)  
> -> 10.112.187.58:5671(http://10.112.187.58:5671/))
>  
>  
> =ERROR REPORT==== 30-Apr-2014(http://airmail.calendar/2014-04-30%2012:00:00%20GMT+4)::20:28:42  
> ===
> error on AMQP connection <0.6368.18>: {ssl_upgrade_error,timeout}  
> (unknown POSIX error)
>  
> =ERROR REPORT==== 30-Apr-2014(http://airmail.calendar/2014-04-30%2012:00:00%20GMT+4)::20:28:42  
> ===
> error on AMQP connection <0.6373.18>: {ssl_upgrade_error,timeout}  
> (unknown POSIX error)
>  
>  
>  
>  
> Can
> anybody
> let me know whether the issue with my code or with RabbitMq configuration,  
> you can see my code HERE(https://gist.github.com/loganathan-s/22256c01127065c9d659).  

The initializer is loaded multiple times (I'm very rusty on Rails and Passenger to suggest why).
You need to change your code to not connect N times if $connection is not nil and alive.

And as I said before, if you don't use Thin or EventMachine heavily, please migrate from amqp
gem to Bunny ASAP. You will see your initializer code become much more straightforward
and easier to debug. 
--  
MK  

Software Engineer, Pivotal/RabbitMQ


More information about the rabbitmq-discuss mailing list