AMQP延迟传递并防止重复消息
我有一个会偶尔生成消息的系统,我只想每 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
处理消息状态不是 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.