【问题标题】:bridging mqtt brokers hivemq and mosquitto桥接 mqtt 代理 hivemq 和 mosquitto
【发布时间】:2015-08-18 19:23:06
【问题描述】:

我正在尝试在同一系统上桥接两个 MQTT 代理,HiveMQMosquittoHiveMQ 正在端口 1884 上工作,Mosquitto 正在 1883 上运行。但是,当我使用mosquitto_pub 命令在端口1883 上发布到mosquitto 代理时,它不会显示在端口1884 上(使用MQTT.fx 作为客户端订阅端口1884 上的所有主题)

这是我只为mosquitto 代理配置了一个网桥。 当我也配置HiveMQ 时,它只在HiveMQ 命令窗口上显示unable to connect to Bridge1, disconnected 消息。我已经包含了下面的配置。请有人帮忙。

mosquitto.config 文件中,我在bridges 下完成了以下操作。

    connection hivemq
    address 127.0.0.1:1884 
    start_type automatic
    clientid clientno1
    notifications true

同时,我还编辑了 HiveMQ bridges.xml 文件以供阅读

<?xml version="1.0" encoding="UTF-8"?>
<bridges xsi:noNamespaceSchemaLocation="http://www.hivemq.com/bridges/bridge.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

<bridge>
    <connectionName>Bridge1</connectionName>
    <addresses>
        <address>
            <host>localhost</host>
            <port>1883</port>
        </address>
    </addresses>
    <clientId>bridgeClient</clientId>
    <topicPatterns>
        <topicPattern>
            <topic>#</topic>
            <qos>1</qos>
            <direction>both</direction>
            <localPrefix>local/</localPrefix>
            <remotePrefix>remote/</remotePrefix>
        </topicPattern>
    </topicPatterns>
    <cleanSession>true</cleanSession>
    <idleTimeout>10</idleTimeout>
    <notificationsEnabled>true</notificationsEnabled>
    <tryPrivate>true</tryPrivate>

</bridge>

显示的图像是当我在另一个系统上尝试相同的过程时。在这里,经纪人被桥接。与我之前所做的比较,唯一的区别是在我的原始系统上没有声明说在 1883 上打开 ipv4 侦听套接字。这是问题吗?

【问题讨论】:

    标签: mqtt bridge mosquitto hivemq


    【解决方案1】:

    桥接应该只在发布者/客户端设置(在你的情况下是 mosquitto),在 Hivemq(服务器)上保留默认设置应该没问题

    尝试更改您的 mosquitto.conf

    connection bridge-mosquitto-to-hivemq
    address 127.0.0.1:1884 
    topic room1/# both 2 sensor/ myhouse/
    bridge_protocol_version mqttv311
    notifications true
    cleansession true
    try_private true
    

    重启代理后,在 mosquitto 代理,尝试在下面发布示例消息

    mosquitto_pub -t sensor/room1/temperature -m '26.3'
    

    【讨论】:

      【解决方案2】:

      您应该只需要在其中一个代理中配置网桥,为两者配置网桥会导致问题,最有可能是消息循环

      对于您的 mosquitto 配置,您需要将 topic 行添加到您的 mosquitto 桥接器,以便它知道要向 hive 代理发送(和接收)哪些主题

      有关主题指令的完整详细信息可以在 mosquitto.conf 手册页 (http://mosquitto.org/man/mosquitto-conf-5.html) 中找到,但基本内容如下:

      主题模式 [[[ out |在|两者] qos-level] local-prefix remote-prefix]

      双向镜像所有主题

      topic # both
      

      【讨论】:

      • 我只在mosquitto上配置了网桥,现在也在配置文件的主题行中添加了。仍然没有桥接。
      • mosquitto 输出是否显示了有关桥的任何信息?
      • 什么都没有。我无法判断它是否已配置。两者都完全独立地工作,但mosquitto 没有显示任何关于桥的信息。我有点困惑。
      • 当我尝试通过 HiveMQ 而不是 mosquitto 配置网桥时,它会显示 trying to connect to bridge 'mosquitto' with target localhost:1883 然后是 Connected to bridge 'mosquitto' with target localhost:1883 然后立即更改为 bridge mosquitto got disconnected. restarting bridge in 30 seconds
      • 如果 mosquitto 没有说明任何关于桥的信息,请尝试将其作为 mosquitto -v 启动以启用所有日志记录。