[rabbitmq-discuss] Prevent to deliver a message to a certain consumer

Simon MacMullen simon at rabbitmq.com
Wed Dec 14 17:00:27 GMT 2011

Here is one approach you could use. Let's stick with the idea that 
you're using routing keys for the chat room name. Furthermore each 
client publishes messages with a "user" header set to the user name.

So you have some top level exchange (presumably direct or topic) for 
chat room routing. When a new user comes on line, rather than just 
declaring a queue and binding to that exchange, they:

* Declare a fanout exchange.

* Declare a headers exchange and bind that to the top level exchange. 
The headers exchange should have its alternate-exchange set to point to 
the fanout exchange.

* Declare a "junk" queue, with message TTL 0, and bind this to their 
headers exchange with arguments ["user": <their username>].

* Declare a "message" queue and bind this to the fanout exchange.

So when they publish a message it goes to the headers exchange. This 
routes it to the junk queue where it expires immediately.

When someone else publishes a message it goes to the headers exchange. 
This can't route it, which makes it go to the alternate fanout exchange. 
This then routes it to the message queue.

The key point is the use of alternate-exchange for negation.

It's a tiny bit fiddly though, so an alternate approach would be to 
write your own exchange type.

Cheers, Simon

On 14/12/11 14:18, bill_martin at freenet.de wrote:
> Hi,
> I am writing an application which allows users to communicate with each
> other via RabbitMQ.
> Each user-application contains a producer and a receiver to publish or
> receive messages to/from a direct exchange. Each user can bind to a
> "chat-room".
> Imagine two users (UserA and UserB). UserA binds to "chatRoom1" and
> UserB binds to "chatRoom1".
> If UserA publishes a message in "chatRoom1" the consumer of the
> user-application from UserB and the consumer of the user-application
> from UserA gets the message.
> I want to prevent that a user gets his own messages to reduce network
> traffic.
> Is it possible?
> Thanks in advance for your help!
> Kind regards,
> Bill
> ---
> *E-Mail ist da wo du bist!* Jetzt mit freenetMail ganz bequem auch
> unterwegs E-Mails verschicken.
> Am besten gleich informieren unter
> http://mail.freenet.de/mobile-email/index.html
> _______________________________________________
> rabbitmq-discuss mailing list
> rabbitmq-discuss at lists.rabbitmq.com
> https://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss

Simon MacMullen
RabbitMQ, VMware

More information about the rabbitmq-discuss mailing list