Add support for queue_unbind, which is supported by RabbitMQ as an extension to the 0-8 protocol.
Thanks to Hasan Alayli <halayli@...> for a patch.
1.1 --- a/CHANGES Mon Apr 04 21:22:50 2011 -0500
1.2 +++ b/CHANGES Tue Apr 05 21:26:46 2011 -0500
1.3 @@ -27,6 +27,9 @@
1.4 creation time. Message application_header strings are assumed to be
1.5 encoded as UTF-8
1.6
1.7 + Add support for queue_unbind, since RabbitMQ supports it as an extension
1.8 + to the 0-8 protocol.
1.9 +
1.10
1.11 Version 0.6.1
1.12
2.1 --- a/amqplib/client_0_8/channel.py Mon Apr 04 21:22:50 2011 -0500
2.2 +++ b/amqplib/client_0_8/channel.py Tue Apr 05 21:26:46 2011 -0500
2.3 @@ -1104,6 +1104,93 @@
2.4 pass
2.5
2.6
2.7 + def queue_unbind(self, queue, exchange, routing_key='',
2.8 + nowait=False, arguments=None, ticket=None):
2.9 + """
2.10 + NOTE::::This is not part of AMQP 0-8, but RabbitMQ supports this as
2.11 + an extension
2.12 +
2.13 + unbind a queue from an exchange
2.14 +
2.15 + This method unbinds a queue from an exchange.
2.16 +
2.17 + RULE:
2.18 +
2.19 + If a unbind fails, the server MUST raise a connection exception.
2.20 +
2.21 + PARAMETERS:
2.22 + queue: shortstr
2.23 +
2.24 + Specifies the name of the queue to unbind.
2.25 +
2.26 + RULE:
2.27 +
2.28 + The client MUST either specify a queue name or have
2.29 + previously declared a queue on the same channel
2.30 +
2.31 + RULE:
2.32 +
2.33 + The client MUST NOT attempt to unbind a queue that
2.34 + does not exist.
2.35 +
2.36 + exchange: shortstr
2.37 +
2.38 + The name of the exchange to unbind from.
2.39 +
2.40 + RULE:
2.41 +
2.42 + The client MUST NOT attempt to unbind a queue from an
2.43 + exchange that does not exist.
2.44 +
2.45 + RULE:
2.46 +
2.47 + The server MUST accept a blank exchange name to mean
2.48 + the default exchange.
2.49 +
2.50 + routing_key: shortstr
2.51 +
2.52 + routing key of binding
2.53 +
2.54 + Specifies the routing key of the binding to unbind.
2.55 +
2.56 + arguments: table
2.57 +
2.58 + arguments of binding
2.59 +
2.60 + Specifies the arguments of the binding to unbind.
2.61 +
2.62 + """
2.63 + if arguments is None:
2.64 + arguments = {}
2.65 +
2.66 + args = AMQPWriter()
2.67 + if ticket is not None:
2.68 + args.write_short(ticket)
2.69 + else:
2.70 + args.write_short(self.default_ticket)
2.71 + args.write_shortstr(queue)
2.72 + args.write_shortstr(exchange)
2.73 + args.write_shortstr(routing_key)
2.74 + #args.write_bit(nowait)
2.75 + args.write_table(arguments)
2.76 + self._send_method((50, 50), args)
2.77 +
2.78 + if not nowait:
2.79 + return self.wait(allowed_methods=[
2.80 + (50, 51), # Channel.queue_unbind_ok
2.81 + ])
2.82 +
2.83 +
2.84 + def _queue_unbind_ok(self, args):
2.85 + """
2.86 + confirm unbind successful
2.87 +
2.88 + This method confirms that the unbind was successful.
2.89 +
2.90 + """
2.91 + pass
2.92 +
2.93 +
2.94 def queue_declare(self, queue='', passive=False, durable=False,
2.95 exclusive=False, auto_delete=True, nowait=False,
2.96 arguments=None, ticket=None):
2.97 @@ -2589,6 +2676,7 @@
2.98 (50, 21): _queue_bind_ok,
2.99 (50, 31): _queue_purge_ok,
2.100 (50, 41): _queue_delete_ok,
2.101 + (50, 51): _queue_unbind_ok,
2.102 (60, 11): _basic_qos_ok,
2.103 (60, 21): _basic_consume_ok,
2.104 (60, 31): _basic_cancel_ok,
3.1 --- a/tests/client_0_8/test_channel.py Mon Apr 04 21:22:50 2011 -0500
3.2 +++ b/tests/client_0_8/test_channel.py Tue Apr 05 21:26:46 2011 -0500
3.3 @@ -245,6 +245,16 @@
3.4 self.assertEqual(msg, msg2)
3.5
3.6
3.7 + def test_unbind(self):
3.8 + self.ch.access_request('/data', active=True, write=True, read=True)
3.9 +
3.10 + my_routing_key = 'unittest.test_queue'
3.11 +
3.12 + qname, _, _ = self.ch.queue_declare()
3.13 + self.ch.queue_bind(qname, 'amq.direct', routing_key=my_routing_key)
3.14 + self.ch.queue_unbind(qname, 'amq.direct', routing_key=my_routing_key)
3.15 +
3.16 +
3.17 def main():
3.18 suite = unittest.TestLoader().loadTestsFromTestCase(TestChannel)
3.19 unittest.TextTestRunner(**settings.test_args).run(suite)