Reputation: 2495
I have a RabbitMQ queues for documents generation. Basically, each document has type
and state
(new, processing, ready), so I use topic exchange with routing keys like type.state
. Every time document changes I send the message with last document description to the exchange and it works good enough.
However sometimes document can be processed twice:
report.new
is sent to exchange.report.new
for the same document is sent.For now I'm just add small code into workers, comparing last_modified
document key from the message with the one from the database and ack the message if they are not the same. However I don't think this is the best solution.
My idea is to add ID
to message headers and have some RabbitMQ plugin which will remove older messages with the same ID
from the queue.
Thanks.
P.S. Maybe another MQ engine can be useful here? E.g. maybe ActiveMQ has such a feature?
Upvotes: 6
Views: 16664
Reputation: 2556
As you wrote, ActiveMQ has "duplicate message detection", but it works differently. It does not remove old message from the queue but it does not add new message to it instead. So it works the same as plugin for RabbitMQ.
Upvotes: 1
Reputation: 15030
You can check this plugin I wrote which allows to de-duplicate messages published within the broker.
You can de-duplicate on the exchange or at the queue according to your needs. Only thing your publisher needs to do is to set the x-deduplicate-message
message header with the ID
of your message.
Upvotes: 7
Reputation: 2495
Ok, i've read about RabbitMQ inner architecture and find out it's impossible. So the way around for somebody looking for it.
ID
in message bodyID
value is timestamp of last worker run for this ID
.Upvotes: 10