【发布时间】:2016-10-07 12:32:26
【问题描述】:
我正在编写一个自动化测试来测试消费者。到目前为止,我在发布消息时不需要包含标题,但现在我需要。而且它似乎缺少文档。
这是我的出版商:
class RMQProducer(object):
def __init__(self, host, exchange, routing_key):
self.host = host
self.exchange = exchange
self.routing_key = routing_key
def publish_message(self, message):
connection = pika.BlockingConnection(pika.ConnectionParameters(self.host))
channel = connection.channel()
message = json.dumps(message)
channel.basic_publish(exchange=self.exchange,
routing_key=self.routing_key,
body=message)
我想做 smtn 之类的:
channel.basic_publish(exchange=self.exchange,
routing_key=self.routing_key,
body=message,
headers={"key": "value"})
在此邮件中添加标头的正确方法是什么?
【问题讨论】:
-
你可以看看我在这里为 pika 提供的一个例子,关于如何添加标题。 github.com/eandersson/python-rabbitmq-examples/blob/master/…
-
这里还有我自己的 amqp 库的另一个示例github.com/eandersson/amqpstorm/blob/stable/examples/…