简体   繁体   English

Paho Python 客户端版本 1.6.1 和 MQTTv5 ResponseTopic

[英]Paho Python client version 1.6.1 and MQTTv5 ResponseTopic

I am using the mosquitto broker with the mqtt vcpkg C++ client.我将 mosquitto 代理与 mqtt vcpkg C++ 客户端一起使用。
I can use the v5 properties to publish messages with a reply topic.我可以使用 v5 属性发布带有回复主题的消息。
When I tried with the Paho Python client, I had no reply topic in the message received on the C++ side.当我尝试使用 Paho Python 客户端时,我在 C++ 端收到的消息中没有回复主题。
I followed some guidelines here for the python side:在这里遵循了 python 方面的一些准则:

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但是当 C++ 客户端在处理程序中收到消息时

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.得到一个空的props值。

As mentioned in the comments, you need to pass the properties to the publish function not connect如评论中所述,您需要将属性传递给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)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM