diff --git a/CHANGELOG.md b/CHANGELOG.md index d47a25764d699c5f636708ffdc222763f4aa089e..9e37c07085f3916ed6e0c28c31e4a1d10351ec6a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ # v1.2.1 -* _TBA_ +* enabled declaring anonymous queues # v1.2 diff --git a/coolamqp/__init__.py b/coolamqp/__init__.py index b6974b05e5a327346bef5b8527dda0e3532b1b10..3f262a6347da4a5fbac352d050c1fa0a409f7b75 100644 --- a/coolamqp/__init__.py +++ b/coolamqp/__init__.py @@ -1 +1 @@ -__version__ = '1.2.1_a1' +__version__ = '1.2.1' diff --git a/coolamqp/attaches/declarer.py b/coolamqp/attaches/declarer.py index cd7888517d5575db0b0521ee81cae7d661c1a5bd..94289a3a1e846845543a2c2c57b97ad7e211bd73 100644 --- a/coolamqp/attaches/declarer.py +++ b/coolamqp/attaches/declarer.py @@ -138,6 +138,9 @@ class Operation(object): self.obj) # todo access not threadsafe self.declarer.on_discard(self.obj) else: + if isinstance(payload, QueueDeclareOk) and self.obj.anonymous: + self.obj.name = payload.queue + self.span_finished() if self.fut is not None: self.fut.set_result(None) @@ -282,10 +285,6 @@ class Declarer(Channeler, Synchronized): :return: a Future instance :raise ValueError: tried to declare anonymous queue """ - if isinstance(obj, Queue): - if obj.anonymous: - raise ValueError('Cannot declare anonymous queue, use consume to have the name filled in!') - if span is not None: enqueued_span = self.cluster.tracer.start_span('Enqueued', child_of=span) else: diff --git a/coolamqp/objects.py b/coolamqp/objects.py index 5ac2516040bb0d5121ebb6f845cb86285c7ebdb7..8ccfe61ebed072b9297d294237e3117954be353d 100644 --- a/coolamqp/objects.py +++ b/coolamqp/objects.py @@ -288,6 +288,12 @@ class QueueBind(object): self.exchange = tobytes(exchange) # type: bytes self.routing_key = tobytes(routing_key) # type: bytes + def __eq__(self, other): + return self.queue == other.queue and self.exchange == other.exchange and self.routing_key == other.routing_key + + def __hash__(self): + return hash(self.queue) ^ hash(self.exchange) ^ hash(self.routing_key) + class NodeDefinition(object): """ diff --git a/tests/test_clustering/test_a.py b/tests/test_clustering/test_a.py index b7ac229758549ec0ccee27e9ca9eda85347683bd..daa86c0293c6849018edac50e3a9b077de79f2ab 100644 --- a/tests/test_clustering/test_a.py +++ b/tests/test_clustering/test_a.py @@ -60,11 +60,6 @@ class TestA(unittest.TestCase): self.c.publish(Message(data), routing_key=b'hello', confirm=True).result() - # rmsg = self.c.drain(3) - # rmsg.ack() - - # self.assertEquals(rmsg.body, data) - def test_actually_waits(self): a = monotonic() @@ -85,6 +80,13 @@ class TestA(unittest.TestCase): time.sleep(1) self.assertEquals(con.qos, (0, 110)) + def test_declare_anonymous(self): + xchg = Exchange('wtfzomg', type='fanout') + q = Queue(exchange=xchg) + self.c.declare(xchg).result() + self.c.declare(q).result() + self.assertTrue(q.name) + def test_anonymq(self): q = Queue(exchange=Exchange(u'ooo', type=b'fanout', auto_delete=True), auto_delete=True) @@ -93,7 +95,7 @@ class TestA(unittest.TestCase): f.result() - self.assertIsNotNone(q.name) + self.assertTrue(q.name) def test_send_recv_zerolen(self): P = {'q': False}