How to add a header key:value pair when publishing a message with pika
<p>I am writing an automated test to test a consumer. So far I did not need to include a header when publishing messages but now I do. And it seems like its lacking documentation.</p>

<p>This is my publisher:</p>

<pre><code>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)
</code></pre>

<p>I want to do smtn like:</p>

<pre><code>channel.basic_publish(exchange=self.exchange,
                      routing_key=self.routing_key,
                      body=message,
                      headers={"key": "value"})
</code></pre>

<p>Whats the correct way to add headers to this message?</p>