【问题标题】:Spring AMQP Rabbit template send timeoutSpring AMQP Rabbit 模板发送超时
【发布时间】:2014-04-25 03:26:45
【问题描述】:

我正在使用 Spring AMQP 库 (1.1.4.Release) 将消息发送到 Rabbit MQ Exchange。我专门使用 RabbitTemplate.correlationconvertAndSend() 方法。此 RabbitTemplate 是使用 CachingConnectionFactory 创建的,其中 PublisherConfirmsPublisherReturns 设置为 true

最近我们遇到了一个网络问题,生产者和消费者在发送消息的过程中都关闭了与 RabbitMQ 代理/交换的连接。这导致org.springframework.amqp.AmqpIOException: java.net.SocketException: Broken pipe 被抛出。然而问题是这个异常在超过 150 秒后被抛出。这导致所有线程长时间处于阻塞状态。

有什么方法可以设置超时,以便我可以设置以便我可以及早获得反馈并采取适当的措施。我更多地考虑了 http 或 db 调用的超时值。 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)

【问题讨论】:

  • 更新——问题出在 RabbitMQ 的流量控制机制上,它会在高流量期间限制发布者。rabbitmq.com/memory.html#per-connection。 @francois-gergaud,您知道在 RabbitMQ 服务器限制的情况下回复超时是否有效,即我的发布者客户端会知道连接过载并可能采取补救措施。

标签: java spring timeout rabbitmq amqp


【解决方案1】:

如果您使用的是 spring-amqp API,您应该能够根据您的连接工厂声明一个 amqp-template 对象,如下所示:

<rabbit:template id="amqpTemplate" 
        connection-factory="rabbitMQConnectionFactory" 
        reply-timeout="60000"/>

这个方法比rabbitMQ客户端提供的连接超时更高级。它似乎在客户端发送接收过程中进行管理,在到达套接字层之前。

希望对您有所帮助。

【讨论】:

    猜你喜欢
    • 2016-12-09
    • 2020-04-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-01
    • 1970-01-01
    • 2017-01-19
    • 2022-06-11
    相关资源
    最近更新 更多