From f7cf85333c1c8e8df3acc9ec2eb01a2dbc9f7709 Mon Sep 17 00:00:00 2001 From: Mark McLoughlin Date: Mon, 26 Aug 2013 10:09:16 +0100 Subject: [PATCH] Don't include msg_id or reply_q in casts On the server side, we only send replies if the request included a _msg_id key. Also, the _reply_q key is only used when we wish to send a reply. So, in order to retain the exact same on-the-wire behaviour and ensure servers aren't sending replies where none is needed, only include these keys if we're doing a call (i.e. wait_for_reply=True). Change-Id: Iac329493252be7d94b1ebe24f00e4d3f5c61d269 --- oslo/messaging/_drivers/amqpdriver.py | 11 ++++++----- tests/test_rabbit.py | 7 +++---- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/oslo/messaging/_drivers/amqpdriver.py b/oslo/messaging/_drivers/amqpdriver.py index cfbd16108..6a4677ad0 100644 --- a/oslo/messaging/_drivers/amqpdriver.py +++ b/oslo/messaging/_drivers/amqpdriver.py @@ -316,14 +316,15 @@ class AMQPDriverBase(base.BaseDriver): context = Context(ctxt) msg = message - msg_id = uuid.uuid4().hex - msg.update({'_msg_id': msg_id}) - LOG.debug('MSG_ID is %s' % (msg_id)) + if wait_for_reply: + msg_id = uuid.uuid4().hex + msg.update({'_msg_id': msg_id}) + LOG.debug('MSG_ID is %s' % (msg_id)) + msg.update({'_reply_q': self._get_reply_q()}) + rpc_amqp._add_unique_id(msg) rpc_amqp.pack_context(msg, context) - msg.update({'_reply_q': self._get_reply_q()}) - if envelope: msg = rpc_common.serialize_msg(msg) diff --git a/tests/test_rabbit.py b/tests/test_rabbit.py index 142252ca9..c2abf2ac9 100644 --- a/tests/test_rabbit.py +++ b/tests/test_rabbit.py @@ -97,7 +97,7 @@ class TestRabbitTransportURL(test_utils.BaseTestCase): target = messaging.Target(topic='testtopic') - driver.send(target, {}, {}) + driver.listen(target) self.assertEquals(passed_params[0], self.expected) @@ -368,10 +368,9 @@ class TestRequestWireFormat(test_utils.BaseTestCase): received = msgs[0] received['oslo.message'] = jsonutils.loads(received['oslo.message']) + # FIXME(markmc): add _msg_id and _reply_q check expected_msg = { - '_msg_id': self.uuids[0].hex, - '_unique_id': self.uuids[1].hex, - '_reply_q': 'reply_' + self.uuids[2].hex, + '_unique_id': self.uuids[0].hex, } expected_msg.update(self.expected) expected_msg.update(self.expected_ctxt)