Reputation: 1215
I am using the mosquitto broker with the mqtt vcpkg C++ client.
I can use the v5 properties to publish messages with a reply topic.
When I tried with the Paho Python client, I had no reply topic in the message received on the C++ side.
I followed some guidelines here for the python side:
from paho.mqtt.properties import Properties
from paho.mqtt.packettypes import PacketTypes
from paho.mqtt.client import Client
properties=Properties(PacketTypes.PUBLISH)
properties.ResponseTopic="myreplies"
client = Client(client_id = "client_1",protocol=5)
client.connect("localhost",properties=properties)
publisher.publish(topic = "acquisition/FifoServerParams", payload = "message")
but when the C++ client receives the message in the handler
client->set_v5_publish_handler(
[&](mqtt::optional<async_client_t::packet_id_t>, mqtt::publish_options, mqtt::buffer topicName, mqtt::buffer contents, mqtt::v5::properties props)
gots an empty props
value.
Upvotes: 1
Views: 953
Reputation: 59608
As mentioned in the comments, you need to pass the properties to the publish
function not connect
from paho.mqtt.properties import Properties
from paho.mqtt.packettypes import PacketTypes
from paho.mqtt.client import Client
properties=Properties(PacketTypes.PUBLISH)
properties.ResponseTopic="myreplies"
client = Client(client_id = "client_1",protocol=5)
client.connect("localhost")
publisher.publish(topic = "acquisition/FifoServerParams", payload = "message", properties = properties)
Upvotes: 3