简体   繁体   English

MQTT RaspberryPi经纪人

[英]MQTT RaspberryPi Broker

I have a small doubt about using MQTT in my project. 我对在项目中使用MQTT存有疑问。 I just wanted to know if it is possible that I use RaspberryPi as MQTT broker (server) to receive data from a device which is publishing in MQTT and then at the same time this RaspberryPi publishes the same data in MQTT to another subscriber? 我只是想知道是否有可能使用RaspberryPi作为MQTT代理(服务器)从正在MQTT中发布的设备接收数据,然后与此同时RaspberryPi将MQTT中的相同数据发布给另一个订户? If it is possible, then what would be the message broker in the second part? 如果有可能,那么第二部分中的消息代理将是什么? I mean, I want the RaspberryPi to be the device controller(to act on the device data) and at the same time to publish the data to another MQTT subscriber. 我的意思是,我希望RaspberryPi成为设备控制器(对设备数据起作用),同时将数据发布给另一个MQTT订阅者。 Is this possible? 这可能吗?

Thank you so much, Pouya 真的很谢谢你Pouya

Pub/sub protocols like MQTT support a one to many approach to data delivery. MQTT之类的发布/订阅协议支持数据传输的一对多方法。 The broker is the central distribution point for data can handle many different clients. 代理是数据可以处理许多不同客户端的中央分发点。

When a client published a message the broker will deliver that message to all clients that have subscribed to the topic that message is published to. 当客户发布消息时,代理将将该消息传递给已订阅该消息发布主题的所有客户。

You can run multiple clients on the same machine each publishing, subscribing or both at the same time 您可以在同一台计算机上运行多个客户端,每次发布,订阅或同时运行

Actually, this is what MQTT do! 实际上,这就是MQTT所做的!

If Device A (Publisher) publish a message in a Topic say: pi-topic/xxxx to MQTT Broker running in Raspberry Pi.Then you just make you Device B (Subscriber) to subscribe/listen to the same topic ie pi-topic/xxxx .In this way, you can achieve it.You can use any library like Paho. 如果设备A(发布者)在主题中发布消息,则说:pi-topic / xxxx到在Raspberry Pi中运行的MQTT Broker。那么,您只需使设备B(订阅者)订阅/收听同一主题,即pi-topic / xxxx。通过这种方式,您可以实现它。您可以使用任何类似Paho的库。

You need to read further about PUB-SUB models and Queue mechanism .It will help in future. 您需要进一步了解PUB-SUB模型和Queue机制。它将对将来有所帮助。

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

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