AMQP延迟传递和防止重复的消息

AMQP延迟传递和防止重复的消息

本文介绍了AMQP延迟传递和防止重复的消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



我正在使用AMQP(RabbitMQ),有没有办法要在rabbitmq或AMQP协议中完成这个?我可以检查一个队列的内容,以确保我不插入重复的?看来,队列检查是一个坏主意,通常不应该对消息系统做些什么。



没有队列检查,这可以通过这些工具来实现吗?唯一想到的解决方案是拥有所有消息的第二个队列,然后消费者读取每个消息并将其置于内部队列中,等待5分钟,并且丢弃任何接收到的重复消息。延迟之后,单个消息被放在要处理的真实队列中。



似乎这可能是一个常见的情况,即队列系统可以处理。任何想法?

解决方案

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



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


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?

解决方案

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.

这篇关于AMQP延迟传递和防止重复的消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-07 05:30