[rabbitmq-discuss] Does rabbitmq support publishing message with a wildcard?

Michael Klishin mklishin at gopivotal.com
Thu Apr 10 11:08:41 BST 2014


On 10 April 2014 at 14:02:04, qihang zhang (qihangzp at gmail.com) wrote:
> > Does rabbitmq support publishing message with wildcard?
> Something I wish like this:
> declare(exchange, 'topic')
> > bind(q1, exchange, 'user1.client1')
> > bind(q2, exchange, 'user1.client2')
> > bind(q3, exchange, 'user1.client3')
> >
> > exchange.publish(msg, routing_key='user1.*') # all of q1,  
> q2, q3 would receive this msg
> > exchange.publish(msg, routing_key='user1.client1') #  
> only q1 would receive this msg
>  
>  
> I read the doc and searched about this, found it seems that only  
> binding with wildcart is supported,
> Now I have to write codes like:
> > declare(exchange_fanout, 'fanout')
>  
>  
> > bind(q1, exchange_fanout)
> >
> > bind(q2, exchange_fanout)
> > bind(q3, exchange_fanout)
> >
> > declare(exchange_direct, 'direct')
> > bind(q1, exchange_direct, 'user1.client1')
> >
> > bind(q2, exchange_direct, 'user1.client2')
> >
> > bind(q3, exchange_direct, 'user1.client3')
> >
>  
>  
> > exchange_fanout.publish(msg) # all of q1, q2, q3 would receive  
> this msg
> > exchange_direct.publish(msg, routing_key='user1.client1')  
> # only q1 would receive this msg
>  
>  
> Is there other clearer way to do these? I think this is a pretty  
> common thing when we want publish msgs peer-to-peer and peer-to-group.  
> Many thanks! :)

This is what topic exchanges are for, see tutorial 5 (and maybe 3, to contrast):
http://www.rabbitmq.com/getstarted.html 
--  
MK  

Software Engineer, Pivotal/RabbitMQ


More information about the rabbitmq-discuss mailing list