mosquitto(2):mosquitto桥接

2017-11-17  本文已影响154人  不想再当程序猿

我之前看过一个博客上面说的是怎么去搭建mosquitto集群(http://www.cnblogs.com/yinyi521/p/6084029.html),但是其实只是使用了桥接的方式将几个服务器连接在一起。可以实现主服务器发布消息,从服务器去接受消息。这种方式显然不是我们支持大量数据接入所需要的一种方式。下面我就记录一下实现桥接的基本步骤:

首先假设我们有三个服务器:

1.1.1.1(主服务器)
1.2.3.4
11.22.33.44

1. 打开mosquitto.conf配置文件:

2. 找到Bridges节点:


建立桥接的时候一定要写两遍,不能把两个服务器写在一个配置里面

connection mytest
address 1.2.3.4:1883
topic room1/# both 2 sensor/ myhouse/
bridge_protocol_version mqttv311
notifications true
cleansession true
try_private true
start_type automatic

connection mytest
address 11.22.33.44:1883
topic room1/# both 2 sensor/ myhouse/
bridge_protocol_version mqttv311
notifications true
cleansession true
try_private true
start_type automatic

3. 启动:

首先先要确保其他两台从服务器已经启动,然后启动主服务器:



我这里只有一台从服务器

4.发布和订阅:

5.注意:

上一篇 下一篇

猜你喜欢

热点阅读