[英]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.