recommendations to keep the consumer thread alive forever

232 views
Skip to first unread message

Techie suk

unread,
Jun 20, 2016, 4:47:21 PM6/20/16
to rabbitmq-users
I have a rabbitmq consumer program that consumes messages continuously in the while (true) loop. after sometime the connection object or channel object become null...any idea about what happens? any recommendations to keep the consumer thread alive forever. 

Michael Klishin

unread,
Jun 20, 2016, 4:55:09 PM6/20/16
to rabbitm...@googlegroups.com
Library cannot turn an existing object reference into a null, so something in your code does.
What we recommend is using basicConsume, a consumer implementation that handles exceptions,
and enabling automatic connection recovery.

On Mon, Jun 20, 2016 at 11:47 PM, Techie suk <sukka...@gmail.com> wrote:
I have a rabbitmq consumer program that consumes messages continuously in the while (true) loop. after sometime the connection object or channel object become null...any idea about what happens? any recommendations to keep the consumer thread alive forever. 

--
You received this message because you are subscribed to the Google Groups "rabbitmq-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rabbitmq-user...@googlegroups.com.
To post to this group, send email to rabbitm...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
MK

Staff Software Engineer, Pivotal/RabbitMQ

Techie suk

unread,
Jun 20, 2016, 5:12:23 PM6/20/16
to rabbitmq-users
Thanks for the reply. I have set following,
 factory.setConnectionTimeout(0);
  factory.setHandshakeTimeout(0);
factory.setAutomaticRecoveryEnabled(true);

Even at the startup, program cannot create connection. Throws this exception:
java.util.concurrent.TimeoutException
at com.rabbitmq.utility.BlockingCell.get(BlockingCell.java:77)
at com.rabbitmq.utility.BlockingCell.uninterruptibleGet(BlockingCell.java:111)
at com.rabbitmq.utility.BlockingValueOrException.uninterruptibleGetValue(BlockingValueOrException.java:37)
at com.rabbitmq.client.impl.AMQChannel$BlockingRpcContinuation.getReply(AMQChannel.java:367)
at com.rabbitmq.client.impl.AMQConnection.start(AMQConnection.java:293)
at com.rabbitmq.client.impl.recovery.RecoveryAwareAMQConnectionFactory.newConnection(RecoveryAwareAMQConnectionFactory.java:37)

Michael Klishin

unread,
Jun 20, 2016, 5:20:07 PM6/20/16
to rabbitm...@googlegroups.com
Are you sure that setting timeouts to 0 is a good idea? Do you really need to tweak those timeouts?

Have you checked server logs? That's the first thing to do when investigating a connectivity issue.
Any inbound TCP connection that sends at least 1 byte is logged, even if it times out, doesn't perform protocol handshake correctly, etc.

Techie suk

unread,
Jun 20, 2016, 5:30:44 PM6/20/16
to rabbitmq-users
I was trying timeout settings to solve timeout exception. I restarted the rabbitmq service and removed the timeout settings. Now the the application works. Haven't seen that exception so far. I read that 0 means forever. so TCP connection will not timeout. My application needs to keep consuming the messages all the time. so not sure if i default timeout will cause the application to stop consuming messages after few seconds.

Michael Klishin

unread,
Jun 20, 2016, 5:55:19 PM6/20/16
to rabbitm...@googlegroups.com
Those timeouts only cover initial TCP connection.

See http://www.rabbitmq.com/heartbeats.html. Setting timeouts to infinity is *not* a good idea.
10-30 seconds is optimal for most cases (60 is currently the default).

See also automatic recovery in Java client docs.
Reply all
Reply to author
Forward
0 new messages