Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to get basicproperties header field in pika python from rabbitmq messages?

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.

like image 292
suhprano Avatar asked Nov 19 '12 19:11

suhprano


People also ask

What is the callback function in RabbitMQ pika?

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:

How to use pika to send messages to RabbitMQ?

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.

What does the box in the middle of a RabbitMQ queue mean?

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.

What is the difference between producer and queue in RabbitMQ?

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 .


1 Answers

Nevermind, all I had to do was print prop.headers

like image 107
suhprano Avatar answered Oct 01 '22 14:10

suhprano