def send_to_worker(self, action, msg=''):
if not self.consumer.worker_id:
raise Exception("Routing key not yet received in RPC response.")
routing_key = '%s.%s' % (self.consumer.worker_id, action)
if isinstance(msg, basestring):
self.consumer._channel.basic_publish(exchange=self.exchange,
routing_key=routing_key,
body=msg)
else:
self.consumer._channel.basic_publish(
exchange=self.exchange,
routing_key=routing_key,
properties=pika.BasicProperties(
content_type='application/json',
),
body=json.dumps(msg),
)
评论列表
文章目录