简体   繁体   English

Spring AMQP Rabbit模板发送超时

[英]Spring AMQP Rabbit template send timeout

I am using Spring AMQP libarary (1.1.4.Release) to send messages to a Rabbit MQ Exchange. 我正在使用Spring AMQP库(1.1.4.Release)将消息发送到Rabbit MQ Exchange。 I am specifically using the RabbitTemplate.correlationconvertAndSend() method. 我专门使用RabbitTemplate.correlationconvertAndSend()方法。 This RabbitTemplate is created using a CachingConnectionFactory with PublisherConfirms and PublisherReturns set to true . 该RabbitTemplate是使用CachingConnectionFactory创建的, CachingConnectionFactory PublisherConfirmsPublisherReturns设置为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. 最近,当生产者和消费者在发送消息的过程中都关闭了RabbitMQ Broker / Exchange的连接时,我们遇到了网络问题。 This resulted in a org.springframework.amqp.AmqpIOException: java.net.SocketException: Broken pipe being thrown. 这导致org.springframework.amqp.AmqpIOException: java.net.SocketException: Broken pipe被抛出。 However the problem was that this Exception was being thrown after more than 150s. 但是问题是,此异常在超过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. 我正在考虑更多关于http或db调用的超时值。 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) . RabbitMQ的ConnectionFactory的连接超时值为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)

If you are using the spring-amqp API, you should be able to declare a amqp-template object based your connection factory, as follow: 如果您正在使用spring-amqp API,则应该能够基于连接工厂声明amqp-template对象,如下所示:

<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. 该方法比rabbitMQ客户端提供的连接超时更高。 It seems to be managed during the client send-receive process, before to reach the socket layer. 它似乎在到达套接字层之前在客户端发送-接收过程中进行管理。

Hope it may help. 希望对您有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM