[rabbitmq-discuss] Connection and channel resource management in servlet

Bertrand Guay-Paquet bernie at step.polymtl.ca
Wed Mar 26 16:42:39 GMT 2014


I'm a new RabbitMQ user and I'm struggling to understand how to properly 
manage the client resources. My usage scenario is a java web application 
(servlet) which publishes messages to some queues for asynchronous 
operations (send email, generate thumbnails, etc.) A java client daemon 
consumes these messages via consumers subscribed to queues. I imagine 
this is a pretty typical usage scenario, but I haven't been able to find 
how to manage the associated RabbitMQ resources properly.

My current understanding and questions:
1) I don't see a need to have more than 1 Connection instance in either 
the servlet or the client. This connection should be created on 
application or servlet startup and closed on shutdown. Are there 
pitfalls with long-lived connections or is this all handled by RabbitMQ 

2) How should I handle broken Connections to the broker? If a new one 
must be created, do all the channels need to be reopened as well?

3) It seems like it would be bad practice to create a new channel each 
time a web request wants to publish a message. Should I pool them? Share 
a single one? Use ThreadLocals? Is there a problem if they're never 
closed (the connection would be on shutdown though)? The java client api 
documentation states that channels *should* be closed but that it's not 

4) My tests seem to show that when a subscribed consumer throws an 
exception in handleDelivery(), it consumes the rest of its buffered 
messages and is then terminated. Does that mean I should never throw 
from handleDelivery()? Or should I monitor currently active consumers 
and restart the failed ones?

Thank you very much for any guidance.


More information about the rabbitmq-discuss mailing list