Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
576 views
in Technique[技术] by (71.8m points)

python - Rabbitmq pika.BasicProperties don't send properties in message

I'm using pika to send message to rabbitmq. I need to send additional properties so I'm using pika.BasicProperties, but when I see this message in Wireshark there are no properties added.

My code:

import pika, uuid

connection = pika.BlockingConnection(
    pika.ConnectionParameters(host='localhost'))
channel = connection.channel()

channel.queue_declare(queue='test_60', durable=True, arguments={'x-message-ttl' : 21600000})

routingKey = "test_server"
message = '{"test_int":268,"Timestamp":1610022012203}'

correlation_id = str(uuid.uuid4())
reply_to = "test_60"
message_type = "SendRequest"

channel.basic_publish(exchange='',routing_key=routingKey,
                body=message,properties=pika.BasicProperties(
                headers={"testId": "60"},
                delivery_mode=2,
                correlation_id = correlation_id,
                reply_to = reply_to,
                type = message_type))

print('message sent')
print(correlation_id)

In Wireshark this message looks like this, so there are no properties and I have no idea what is wrong with this example.

enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
 prop = pika.BasicProperties(
            content_type='application/json',
            content_encoding='utf-8',
            headers={'key': 'value'},
            delivery_mode = 1,
        )

        channel.basic_publish(
                exchange='',
                routing_key=qname,
                properties=prop,
                body='{message: hello}'
            )

UI:

enter image description here

Wireshark:

enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...