Add method in Agent class to allow message handling extensions

A new method is added to handle message creation separately from
the send logic. This will allow to extend Agent code by using inheritance
so that there is no need to rewrite send method in order to change
message content.

Closes-Bug: #1444547
Change-Id: I95e35974f7df017383df206293e8a7c93af04489
This commit is contained in:
Georgy Okrokvertskhov 2015-04-15 09:03:58 -07:00 committed by Serg Melikyan
parent 7740580e8b
commit b65203f557

View File

@ -80,6 +80,12 @@ class Agent(murano_object.MuranoObject):
'Use of murano-agent is disallowed '
'by the server configuration')
def _prepare_message(self, template, msg_id):
msg = messaging.Message()
msg.body = template
msg.id = msg_id
return msg
def _send(self, template, wait_results, timeout, _context):
"""Send a message over the MQ interface."""
msg_id = template.get('ID', uuid.uuid4().hex)
@ -88,10 +94,7 @@ class Agent(murano_object.MuranoObject):
listener = self._environment.agentListener
listener.subscribe(msg_id, event, _context)
msg = messaging.Message()
msg.body = template
msg.id = msg_id
msg = self._prepare_message(template, msg_id)
with common.create_rmq_client() as client:
client.send(message=msg, key=self._queue)