RabbitMq 连接超时异常

编程入门 行业动态 更新时间:2024-10-24 14:25:48
本文介绍了RabbitMq 连接超时异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

使用 spring amqp (rabbitmq):

Using spring amqp (rabbitmq):

我的消费者花费相当多的时间来处理消息,有时我的业务逻辑需要超过 2 个小时,但是在处理之后,当我尝试确认 rabbitmq 的基本确认"时,它会引发连接超时异常.

My consumer takes quite a lot of time to process message sometimes my business logic takes more than 2 hours but then after the processing when I try to acknowledge the rabbitmq for "basic ack" it throws connection timeout exception.

我该怎么办?我应该让连接永远存在还是使用心跳?

What should I do ? Should I make connection live forever or use heartbeats ?

推荐答案

考虑在长期业务运营开始后立即确认的替代选项,然后通知其状态:失败或成功,以防万一有任何依赖的演员.

Consider an alternative option with ack-ing right after your long-lasting business operation starts and later informing about its status: either failure or success, in case if you have any dependent actors.

作为 Artem &Gary 建议长时间保存消息是一种非常反模式,您可能希望使该过程真正异步 - 您的服务消耗了一条消息并开始做一些事情:那么好,让我们承认这一点.如果您需要在失败时重复,只需在出现失败时发出单独的消息,以便另一个消费者接收并处理它.

As Artem & Gary suggest that it's quite an anti-pattern to hold messages for a long time, you may want to make the process really async -- your service consumed a message and started doing some stuff: good then, let's acknowledge that. And in case if you need to repeat on failure, just make a separate message once failure appears, so another consumer would take it and process it.

更多推荐

RabbitMq 连接超时异常

本文发布于:2023-11-05 12:33:04,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1560855.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:异常   RabbitMq

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!