AMQP延迟传递并防止重复消息

发布于 2024-07-27 21:46:29 字数 399 浏览 9 评论 0原文

我有一个会偶尔生成消息的系统,我只想每 5 分钟提交零条或一条消息。 如果没有生成消息,队列使用者将不会处理任何内容。 如果 5 分钟内生成一百条相同的消息,我只希望从队列中使用其中一条。

我正在使用AMQP(RabbitMQ),有没有办法在rabbitmq或AMQP协议中完成这个任务? 我可以检查队列的内容以确保不插入重复项吗? 队列检查似乎是一个坏主意,通常不应该为消息传递系统执行此操作。

如果没有队列检查,可以用这些工具来完成吗? 想到的唯一解决方案是使用第二个队列来接收所有消息,然后消费者读取每条消息并将其放入内部队列中,等待 5 分钟,然后丢弃收到的任何重复消息。 延迟后,单个消息将被放入“真实”队列中进行处理。

看起来这可能是一种常见的情况,队列系统可以处理。 有任何想法吗?

I have a system that will generate messages sporadically, and I would like to only submit either zero or one message every 5 minutes. If no message is generated, nothing would be processed by the queue consumer. If a hundred identical messages are generated within 5 minutes I only want one of those to be consumed from the queue.

I am using AMQP(RabbitMQ), is there a way to accomplish this within rabbitmq or the AMQP protocol? Can I inspect a queue's contents to ensure that I don't insert a duplicate? It seems that queue inspection is a bad idea and not typically what should be done for a messaging system.

Without queue inspection, can this be accomplished with these tools? The only solution that comes to mind is have a second queue that takes all messages, then the consumer reads each message and puts it in an internal queue, waits for 5 minutes, and any duplicate messages that are received are discarded. After the delay, the single message is put on the "real" queue to be processed.

It seems like this might be a common situation, that a queue system could handle. Any ideas?

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

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

发布评论

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

评论(1

无名指的心愿 2024-08-03 21:46:29

处理消息状态不是 AMQP 处理的事情。 您可以尝试处理某些进程中的状态,该状态也存在于 AMQ 和代理消息上(就像您在原始问题中所写的那样)。 根据您的情况,您可能可以使用序列或更复杂的无状态重复检测方法,但 AMQP 不处理此特定用例。

唯一可以保证的是,如果多个绑定与随后传递到队列的消息匹配,则实际上仅传递一条消息。

Handling message state is not something that AMQP is dealing with. You could try to handle the state in some process which is also present on the AMQ and proxy messages (like you wrote in your original question). Depending on your situation your maybe could use sequences or more sophisticated means of stateless duplicate detection but AMQP does not handle this specific use case.

The only thing that is guaranteed is that if multiple bindings match a message which is subsequently delivered to a queue only one message is actually delivered.

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