使用 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 连接超时异常
发布评论