[rabbitmq-discuss] How to sanely bind one queue to many exchanges?

Paul Jones pauljones23 at gmail.com
Thu Aug 13 10:54:12 BST 2009


Hi Nathan,

Would it be possible to detail a bit more about your use case, and thus why
you don't know when exchanges will come and go? In most scenarios, we'd
recommend that you just declare the exchanges in a non-passive manner - but
I take it that there is something special about your use case that prevents
this.

If your requirement definitely does stand, there isn't really a cleaner way
to do this from the queue-binding end. Speculating a bit on your use case,
if you're trying to bind every exchange in your system to a single queue,
would it be possible to perform the binding at the point of exchange
creation (ie, instead of a queue binding to a well-known exchange, bind the
exchange to a well-known queue).

Exchange-to-exchange bindings are still just a proposal at the moment I'm
afraid.

Thanks,
Paul.

On Tue, Aug 11, 2009 at 8:20 PM, Nathan Gray <n8gray at n8gray.org> wrote:

> Hi folks,
>
> I'm using rabbitmq as an event notification system.  In my application
> each client will subscribe to a number of exchanges.  Exchanges may
> come and go.  The client cannot be expected to know in advance which
> exchanges no longer exist, so they will use exchange.declare(...,
> passive=True,...) to find out which ones exist.  However,
> exchange.declare in passive mode raises a channel exception and kills
> the channel if the exchange doesn't exist.  Assuming I want to use one
> channel per client I'm stuck with ugly, racy code to subscribe to
> multiple exchanges.  (See the end of the post for the python code to
> do it.)  And if something goes wrong and kills the channel I have to
> go through the whole dance again.  This seems crazy.
>
> My question is, what's the right way for one client to get messages
> from multiple exchanges?  Can one auto-delete queue be bound in
> multiple channels, and if so is that the proper approach?  Should I be
> making N queues & channels to subscribe to N exchanges?
>
> Also, exchange-exchange binding [1] would solve a lot of problems for
> me -- does it work or is it just a proposal?
>
> Thanks,
> -n8
>
> --
> http://n8gray.org
>
> [1]: https://dev.rabbitmq.com/wiki/ExchangeToExchangeBindings
>
> while True:
>    chan = connection.channel()
>    found = []
>    for xc in exchanges:
>        try:
>            chan.exchange_declare(exchange=xc, passive=True, ...)
>            found.append(xc)
>        except amqp.exceptions.AMQPChannelException, e:
>            if e.amqp_reply_code == 404:
>                # Channel got closed.  Open a new channel.
>                chan = connection.channel()
>            else:
>                raise e
>    # Sure hope nothing gets deleted at this point!
>    qname, _, _ = chan.queue_declare(exclusive=True)
>    try:
>        for xc in found:
>            chan.queue_bind(queue=qname, exchange=xc)
>    except amqp.exceptions.AMQPChannelException, e:
>        if e.amqp_reply_code == 404:
>            # Oops, an exchange got deleted.  Start over.
>            continue
>        else:
>            raise e
>    # No exception raised, so we're done (until something
>    # else goes wrong & kills the channel...)
>    break
>
> _______________________________________________
> rabbitmq-discuss mailing list
> rabbitmq-discuss at lists.rabbitmq.com
> http://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.rabbitmq.com/pipermail/rabbitmq-discuss/attachments/20090813/6e7d2c05/attachment.htm 


More information about the rabbitmq-discuss mailing list