How can I unbind only one binding, not the whole queue?

1,153 views
Skip to first unread message

ma...@lindenlab.com

unread,
Dec 18, 2012, 1:11:28 PM12/18/12
to ruby...@googlegroups.com
In my app there is one direct exchange, each consumer has one exclusive queue, and then each queue has multiple bindings with the exchange.
I would like to unbind ONLY one binding, but the amqp documentation for unbind seems to not be able to do this.

    queue.bind(exchange, routing_key: 'id1')
    queue.bind(exchange, routing_key: 'id2')

    queue.unbind(exchange, routing_key: 'id2') #=> Unbind ONLY id2 (DO NOT WORKS)

But the unbind method does not have routing_key option, and will just remove all declared bindings in queue.

How could I unbind only one binding, not the whole queue?
Is there any other pattern I should be using? (for example, I could use multiple queues per consumer, but this looks very inefficient)

--
PD: This question is also in StackOverflow

Michael Klishin

unread,
Dec 27, 2012, 6:51:22 AM12/27/12
to ruby...@googlegroups.com
2012/12/18 <ma...@lindenlab.com>

But the unbind method does not have routing_key option, and will just remove all declared bindings in queue.

This looks like an amq-protocol limitation that is easy to fix. I will look into it soon.

RabbitMQ HTTP API supports removing individual bindings, but it is one of a few operations not implemented in
the Ruby client [1] yet and identifying bindings is a little annoying.

--
MK

http://github.com/michaelklishin
http://twitter.com/michaelklishin

Michael Klishin

unread,
Dec 27, 2012, 6:55:09 AM12/27/12
to ruby...@googlegroups.com


2012/12/27 Michael Klishin <michael....@gmail.com>

This looks like an amq-protocol limitation that is easy to fix. I will look into it soon.

Actually, AMQP::Queue#unbind does support the :routing_key option:
https://github.com/ruby-amqp/amqp/blob/master/lib/amqp/queue.rb#L360

Can you please put together a small example that demonstrates the issue?

Michael Klishin

unread,
Dec 27, 2012, 7:12:53 AM12/27/12
to ruby...@googlegroups.com
2012/12/27 Michael Klishin <michael....@gmail.com>

Actually, AMQP::Queue#unbind does support the :routing_key option:
https://github.com/ruby-amqp/amqp/blob/master/lib/amqp/queue.rb#L360

Can you please put together a small example that demonstrates the issue?


The following test demonstrates that unbinding from a direct exchange with a specific routing key does work:

and the [reference] documentation is now updated:
Reply all
Reply to author
Forward
0 new messages