How to publish a message to a specific client in Mosquitto MQTT

北城余情 提交于 2019-11-29 14:14:25

There is no way to publish a message to a single subscriber at the MQTT protocol level.

One of the key tenants of a pub/sub system is to totally decouple the publisher from the subscribers, there is no way for a publisher to know if there are any subscribers to a given topic let alone target one specifically.

Using a topic for each device is not a problem as their is virtually no overhead in the broker for each topic. You can also use ACLs to ensure that each client can only subscribe their own topic (while still being able to publish to others if needed)

You could use a single topic that all clients subscribe to and encode the target device in the payload and have the device decide if the message is for it's self. The down side to this is that you can't apply ACLs to this model.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!