I'd like to selectively delete messages from an AMQP queue without even reading them.
The scenario is as follows:
Sending side wants to expire messages of type X based on a fact that new information of type X arrived. Because it's very probable that the subscriber didn't consume latest message of type X yet, publisher should just delete previous X-type messages and put a newest one into the queue. The whole operation should be transparent to the subscriber - in fact he should use something as simple as STOMP to get the messages.
How to do it using AMQP? Or maybe it's more convenient in another messaging protocol?
I'd like to avoid a complicated infrastructure. The whole messaging needed is as simple as above: one queue, one subscriber, one publisher, but the publisher must have an ability to ad-hoc deleting the messages for a given criteria.
The publisher client will use Ruby but actually I'd deal with any language as soon as I discover how to do it in the protocol.
You cannot currently do this in RabbitMQ (or more generally, in AMQP) automatically. But, here's an easy workaround.
Let's say you want to send three types of messages: Xs, Ys and Zs. If I understand your question correctly, when an X message arrives, you want the broker to forget all other X messages that haven't been delivered.
This is fairly easy to do in RabbitMQ:
This implies a race condition when two producers send the same type of message at the about the same time. The result is that its possible for the a queue to have two (or more) messages at the same time, but since the number of messages is upper-bounded by the number of producers, and since the superfluous messages are purged on the next publish, this shouldn't be much of a problem.
To summarize, this solution has just one extra step from the optimal solution, namely purge queue X before publishing a message of type X.
If you need any help setting up this configuration, the perfect place to ask for advice is the rabbitmq-discuss mailing list.