Reputation: 63
I am using Spring AMQP libarary (1.1.4.Release) to send messages to a Rabbit MQ Exchange. I am specifically using the RabbitTemplate.correlationconvertAndSend() method. This RabbitTemplate is created using a CachingConnectionFactory
with PublisherConfirms
and PublisherReturns
set to true
.
Recently we had an network issue when both Producer and Consumer had their connections to the RabbitMQ Broker/Exchange closed in the middle of sending a message. This resulted in a org.springframework.amqp.AmqpIOException: java.net.SocketException: Broken pipe
being thrown. However the problem was that this Exception was being thrown after more than 150s. This was causing all the threads to be in Blocked state for extended periods.
Is there any way I can set a timeout so that I can set so that I can get early feedback and take appropriate action. I am thinking more along the lines of a timeout value for an http or db call. RabbitMQ's ConnectionFactory has a connection timeout value http://www.rabbitmq.com/releases/rabbitmq-java-client/v3.1.0/rabbitmq-java-client-javadoc-3.1.0/com/rabbitmq/client/ConnectionFactory.html#setConnectionTimeout(int)
.
Upvotes: 4
Views: 6522
Reputation: 404
If you are using the spring-amqp API, you should be able to declare a amqp-template object based your connection factory, as follow:
<rabbit:template id="amqpTemplate"
connection-factory="rabbitMQConnectionFactory"
reply-timeout="60000"/>
This method is at more higher level than the connection's time-out offered by the rabbitMQ client. It seems to be managed during the client send-receive process, before to reach the socket layer.
Hope it may help.
Upvotes: 2