Skip to content Skip to sidebar Skip to footer

How To Read Header Key:value Pair When Subscribing A Message With Paho Mqtt

I am adding a header key:value pair when publishing a message to my rabbitmq broker using pika like channel.basic_publish(exchange=self.exchange, routing_key=

Solution 1:

Pika is a AMQP client publishing messages in AMQP format.

Paho is a MQTT client and as such can only handle messages in that format. At MQTT v3 (the Paho Python client does not support MQTT v5 yet) the protocol does not have any scope to hold message attributes. The only properties a MQTT v3 message has are topic, payload, QOS and a retained bit.

So the RabbitMQ broker must be doing a format conversion and stripping the attributes off before moving the message from the Queue to the MQTT Topic.

So basically I'm saying there are no attributes in the MQTT message to read.

EDIT: It looks like the latest version of the Paho Python client does support MQTTv5 (the doc has just not been updated). While MQTTv5v does support Key/Value pair attributes in the header, it will depend on the client actually connecting using MQTTv5 and RabbitMQ supporting both MQTTv5 and copying the values over to the new format.

Post a Comment for "How To Read Header Key:value Pair When Subscribing A Message With Paho Mqtt"