RabbitMQ使用者崩溃时,提取的消息会如何处理? [英] What happens to fetched messages when RabbitMQ consumer crashes?

查看:154
本文介绍了RabbitMQ使用者崩溃时,提取的消息会如何处理?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有一个RabbitMQ使用者可以批量检索100条消息,但是在将这些消息标记为已处理之前它崩溃了,这些消息会丢失吗?我希望队列中的每条消息至少被处理一次.建议使用什么方法来处理在确认消息之前崩溃的消费者?

If I have a RabbitMQ consumer that retrieves 100 messages in bulk, but then it crashes before it can mark those messages as processed, are those messages lost? I want every message in the queue to be processed at least once. What's the recommended approach to deal with consumers that crash before they've acknowledged messages?

RabbitMQ是否以某种方式将它们重新放置在队列中,或者我需要做些什么才能使其实现?

Does RabbitMQ put them back on the queue somehow, or what do I need to do to make it happen?

推荐答案

与崩溃的消费者打交道的推荐方法是什么 在他们确认消息之前?

What's the recommended approach to deal with consumers that crash before they've acknowledged messages?

让Rabbitmq为您做所有事情-未确认的消息将重新排队,并将再次传递给另一个(甚至相同的)使用者.

Let the rabbitmq do everything for you - messages that are not acknowledged are re-queued and will be delivered again to another (or even same) consumer.

RabbitMQ是否以某种方式将它们放回队列,或者我需要做什么 做到这一点?

Does RabbitMQ put them back on the queue somehow, or what do I need to do to make it happen?

请参阅第一个问题的答案.只是在处理消息之前不要确认消息.这意味着还要确保未设置auto_ack标志!

See answer to first question. Simply don't acknowledge the messages before they're processed. This means also making sure that auto_ack flag is not set!

如果我有一个RabbitMQ使用者可以批量检索100条消息,但是 然后会崩溃,然后才能将这些消息标记为已处理 这些邮件丢失了吗?

If I have a RabbitMQ consumer that retrieves 100 messages in bulk, but then it crashes before it can mark those messages as processed, are those messages lost?

请参阅上面的答案-如果自动确认,它们就会丢失.
请参考第二篇教程:

See answer above - they are lost if they're automatically acknowledged.
Just a bit of reference, quoting from second tutorial:

如果消费者死亡(其渠道已关闭,连接已关闭或 TCP连接丢失),而无需发送ack,RabbitMQ将 了解消息未完全处理,将对其重新排队. 如果同时有其他消费者在线,则它将 迅速将其交付给另一个消费者.这样你就可以确定 即使工人偶尔死亡,也不会丢失任何消息.

If a consumer dies (its channel is closed, connection is closed, or TCP connection is lost) without sending an ack, RabbitMQ will understand that a message wasn't processed fully and will re-queue it. If there are other consumers online at the same time, it will then quickly redeliver it to another consumer. That way you can be sure that no message is lost, even if the workers occasionally die.

这篇关于RabbitMQ使用者崩溃时,提取的消息会如何处理?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆