def callback(ch, method, properties, body):
prop = properties
print prop
#print prop[1]
#print prop[“headers”]
#print prop.headers()
print body
This is the list from prop:
<BasicProperties(['delivery_mode=2', "headers={'BIProto.ClickEvent': 'BIProto.ClickEvent'}", 'content_type=application/x-protobuf'])>
I'm able to print body and the list of basic properties. But how can I just get headers?
All the #print statements in the function error-ed.
Whenever we receive a message, this callback function is called by the Pika library. In our case this function will print on the screen the contents of the message. Next, we need to tell RabbitMQ that this particular callback function should receive messages from our hello queue:
To install it you can use the pip package management tool: Now we have Pika installed, we can write some code. Our first program send.py will send a single message to the queue. The first thing we need to do is to establish a connection with RabbitMQ server. We're connected now, to a broker on the local machine - hence the localhost.
The box in the middle is a queue - a message buffer that RabbitMQ keeps on behalf of the consumer. Our overall design will look like: Producer sends messages to the "hello" queue. The consumer receives messages from that queue. RabbitMQ speaks multiple protocols.
A program that sends messages is a producer : A queue is the name for a post box which lives inside RabbitMQ. Although messages flow through RabbitMQ and your applications, they can only be stored inside a queue .
Nevermind, all I had to do was print prop.headers
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With