Skip to content
This repository has been archived by the owner on Sep 23, 2020. It is now read-only.

Commit

Permalink
Make fire and call sysname aware
Browse files Browse the repository at this point in the history
  • Loading branch information
oldpatricka committed Jan 17, 2013
1 parent f080e3a commit cdd5700
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions dashi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ def sysname(self):
def name(self):
return self._name

def add_sysname(self, name):
if self.sysname is not None:
return "%s.%s" % (self.sysname, name)
else:
return name

def fire(self, name, operation, args=None, **kwargs):
"""Send a message without waiting for a reply
Expand All @@ -91,11 +97,11 @@ def fire(self, name, operation, args=None, **kwargs):
args = kwargs

d = dict(op=operation, args=args)
headers = {'sender': self.name}
headers = {'sender': self.add_sysname(self.name)}

with producers[self._conn].acquire(block=True) as producer:
maybe_declare(self._exchange, producer.channel)
producer.publish(d, routing_key=name, exchange=self._exchange_name,
producer.publish(d, routing_key=self.add_sysname(name), exchange=self._exchange_name,
headers=headers, serializer=self._serializer)

def call(self, name, operation, timeout=5, args=None, **kwargs):
Expand Down Expand Up @@ -142,12 +148,12 @@ def _callback(body, message):
consumer.declare()

d = dict(op=operation, args=args)
headers = {'reply-to': msg_id, 'sender': self.name}
headers = {'reply-to': msg_id, 'sender': self.add_sysname(self.name)}

with producers[self._conn].acquire(block=True) as producer:
maybe_declare(self._exchange, producer.channel)
log.debug("sending call to %s:%s", name, operation)
producer.publish(d, routing_key=name, headers=headers,
log.debug("sending call to %s:%s", self.add_sysname(name), operation)
producer.publish(d, routing_key=self.add_sysname(name), headers=headers,
exchange=self._exchange, serializer=self._serializer)

with consumer:
Expand Down

0 comments on commit cdd5700

Please sign in to comment.