简体   繁体   English

使用Spring AMQP时,如何正确处理RabbitMQ通道上basicAck的IOException?

[英]How to properly handle IOException for basicAck on RabbitMQ Channel when using Spring AMQP?

When having declared a method like this using Spring AMQP: 当使用Spring AMQP声明了这样的方法时:

@RabbitListener(..)    
public void myMethod(@Header(AmqpHeaders.CHANNEL) Channel channel, @Header(AmqpHeaders.DELIVERY_TAG) Long tag, ...)

and using manual acknowledge mode, how should one properly deal with the IOException that may be thrown when doing ACK: 并使用手动确认模式,如何正确处理执行ACK时可能抛出的IOException

try {
    channel.basicAck(tag, false);
} catch (IOException e) {
  // What to do here?
}

Should the exception be rethrown? 应该重新抛出异常吗? Should the "basicAck" operation be retried? 应该重试“ basicAck”操作吗? What's the proper way to handle it? 处理它的正确方法是什么?

The standard way of doing this is using retry mechanism & to come out if none of them succeeds. 执行此操作的标准方法是使用重试机制&如果它们均未成功,则退出。

However, based on my experience, if channel throws an exception, it more or less means the channel is useless & you might have to redo the whole thing again. 但是,根据我的经验,如果channel引发异常,则或多或少意味着该通道是无用的,您可能必须再次重做整个事情。 I normally log the error along with the required details so that I can track which message processing failed so that I can verify the same later to see if its processed or I need to do anything about it. 我通常将错误和所需的详细信息一起记录下来,以便我可以跟踪哪个消息处理失败,以便以后可以进行验证以查看消息处理是否失败或需要采取任何措施。

暂无
暂无

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

相关问题 RabbitMQ BasicAck 在控制台上提供通道关闭错误消息 - Spring AMQP - RabbitMQ BasicAck giving channel shutdown error messages on console - Spring AMQP 没有连接的AMQP / RabbitMQ通道何时死亡? - when does an AMQP/RabbitMQ channel with no connections die? 带有RabbitMQ的spring-amqp无法正确关闭 - spring-amqp with RabbitMQ does not shutdown properly 使用spring amqp模板清除rabbitmq队列? - purge rabbitmq queue using spring amqp template? 在选择Amqp / RabbitMQ队列(Spring AMQP)之前如何“检查” - How to 'check' before picking off the Amqp/ RabbitMQ Queue (Spring AMQP) 有人可以解释RabbitMQ Channel的确切行为吗? 还有执行channel.basicAck是否关闭通道? - Can someone explains the exact behavior of RabbitMQ Channel? and also if executing channel.basicAck closes the channel? rabbitMQ 与 spring 启动 amqp 连接无穷大错误时 @Sendto 失败 - rabbitMQ with spring boot amqp connection infinity error when @Sendto fail 在RabbitMQ中分组接收到的消息,最好使用Spring AMQP? - Group received messages in RabbitMQ, preferably using Spring AMQP? 是否可以使用Spring-AMQP在RabbitMQ中设置AutomaticRecoveryEnabled? - Is there any option to set AutomaticRecoveryEnabled in RabbitMQ using Spring-AMQP? 使用Spring ChannelAwareMessageListener时如何处理RabbitMQ使用者取消通知 - How do I handle RabbitMQ Consumer Cancellation Notification when using Spring ChannelAwareMessageListener
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM