如果未确认,STOMP RabbitMQ 会重新向订阅者发送消息

发布于 2025-01-09 14:56:21 字数 676 浏览 3 评论 0 原文

客户端使用 STOMP 版本 1.2 而不是 RabbitMQ 版本 3.9.3。
客户端用于聊天应用程序作为传入消息的订阅者。

a["CONNECTED\nserver:RabbitMQ/3.9.3\nsession:session-paGrRWWiEsYECaWdVdqkXQ\nheart-beat:4000,4000\nversion:1.2\nuser-name:6208370595c29c4357f9b81c\n\n\u0000"]

订阅的 ack 标头是client-individual
客户端能够从 RabbitMQ 中确认消息而不会出现任何异常。

问题是,当客户端不确认时,消息不会重新传递给客户端。
如果订阅者没有确认消息,我希望将消息重新传递给订阅者。

是否可以使用 STOMP 和 RabbitMQ 内置解决方案创建这样的功能,而不进行任何自定义确认?

我尝试过的另一种更糟糕的解决方案是,我在rabbitmq.conf中将consumer_timeout设置为10000,这应该断开10秒内没有确认消息的订阅者,然后客户端将重新连接到客户端并获取丢失的消息。 该解决方案的问题在于,在未发送 ack 后断开订阅者需要 1 分钟,而不是 10 秒。

The client uses STOMP version 1.2 over RabbitMQ version 3.9.3.
The client is used for a chat app as a subscriber for incoming messages.

a["CONNECTED\nserver:RabbitMQ/3.9.3\nsession:session-paGrRWWiEsYECaWdVdqkXQ\nheart-beat:4000,4000\nversion:1.2\nuser-name:6208370595c29c4357f9b81c\n\n\u0000"]

The ack header on subscription is client-individual.
The client is able to acknowledge a message without any exceptions from RabbitMQ.

The problem is, when the client doesn't acknowledge, the message isn't redelivered to the client.
I want to have the message redelivered to the subscriber if the subscriber didn't acknowledged the message.

Is it possible to create such a feature using STOMP and RabbitMQ built-in solutions, without doing any custom acknowledges?

The alternative worse solution I tried was that I set up consumer_timeout to 10000 in rabbitmq.conf, which should disconnect a subscriber which doesn't ack a message for 10s, then the client would reconnect to the client and fetch the missed messaged.
The problem with this solution is that it takes 1 minute, not 10 seconds to disconnect a subscriber after not sending ack.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

左耳近心 2025-01-16 14:56:21

nack 消息的处理方式由消息代理决定,在您的例子中是 RabbitMq。它们可以被丢弃、发送到死信队列或重新排队。
这些文档将为您提供帮助:https://www.rabbitmq.com/nack.html

为了使用重新排队机制,您必须在批量情况下使用 basic.rejectbasic.nack
如何设置取决于您使用的客户端库 api。

另请参阅:https://www.rabbitmq.com/confirms.html#消费者 nacks 请求

有时消费者无法立即处理交付,但其他
实例也许​​能够。在这种情况下,可能需要重新排队
并让另一个消费者接收并处理它。基本.拒绝和
basic.nack 是用于此目的的两个协议方法。

这些方法通常用于否定确认交付。
此类交付可以被代理丢弃或重新排队。这
行为由 requeue 字段控制。 当该字段设置为
true,经纪人将重新排队交付(或多次交付,如
将很快解释)与指定的交货标签。


How nack messages are handled is decided by the message broker, in your case RabbitMq. They can either be dropped, sent to a dead letter queue or re-enqueued.
The docs will help you out: https://www.rabbitmq.com/nack.html

In order to use requeuing mechanism you have to use basic.reject or basic.nack in case of bulk.
How you set it depends on the client library api you use.

Also refer to: https://www.rabbitmq.com/confirms.html#consumer-nacks-requeue

Sometimes a consumer cannot process a delivery immediately but other
instances might be able to. In this case it may be desired to requeue
it and let another consumer receive and handle it. basic.reject and
basic.nack are two protocol methods that are used for that.

The methods are generally used to negatively acknowledge a delivery.
Such deliveries can be discarded by the broker or requeued. This
behaviour is controlled by the requeue field. When the field is set to
true, the broker will requeue the delivery
(or multiple deliveries, as
will be explained shortly) with the specified delivery tag.

莫言歌 2025-01-16 14:56:21

嗯...关于使用rabbitmq 时选择哪种配置有很多讨论。我将推荐以下设置(首先)

使用 fanout 模型(如 文档)。这将允许您:

  • 定义一个交换(例如:对于所有广播或公共消息) 为
  • 每个服务定义一个队列(从而允许您的解决方案进行扩展,而无需在多个实例上同时运行相同的服务进行重复)
  • 设置手动确认(似乎更适合您的用例)或否定确认(例如 - 当发生错误时 - 将消息返回给代理)。 此处涵盖了该主题

简而言之:是的,有一个适合您需求的配置
深入:您应该仔细设计您的设置以满足您的所有需求(包括高可用性),以确保您的代码和部署能够随着项目的进展而保持不变

Well...there's lots to discuss about which configuration to choose when using rabbitmq. I will recommend the following setup (to begin with)

Use fanout model (as described in the docs). This will allow you to:

  • Define an exchange (for instance: for all broadcast or public messages)
  • Define a queue per service (thus allowing you solution to scale without having a duplication for the same service running simultaneity on several instances)
  • Set manual acknowledge (seems more suitable for your use case) or negative acknowledgement (e.g. - when something wrong happen - return message back to broker). This topic is covered here

In short: yes, there is a configuration which suits your needs
In depth: you should carefully craft your setup to suit all your needs (including high availability) in order to ensure that your code and deployment will hold as your project progress

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文