【问题标题】:Mosquitto not publishing on SYS topicsMosquitto 不在 SYS 主题上发布
【发布时间】:2015-07-22 04:53:03
【问题描述】:

我使用 mosquitto 服务器作为 mqtt 代理。我测试 mosquitto 的性能,我需要订阅 $SYS 层次结构以获取一些数据,例如当前从 $SYS/broker/clients/active 主题连接的数量。我有以下 mosquitto 配置文件。

# Place your local configuration in /etc/mosquitto/conf.d/
#
# A full description of the configuration file is at
# /usr/share/doc/mosquitto/examples/mosquitto.conf.example

pid_file /var/run/mosquitto.pid

persistence true
persistence_location /var/lib/mosquitto/

log_dest file /var/log/mosquitto/mosquitto.log

include_dir /etc/mosquitto/conf.d

listener 1884
protocol websockets

listener 1883

sys_interval 1

max_connections -1

我正在订阅$SYS/broker/clients/active这样的主题

ubuntu@linux-box:/etc/mosquitto$ mosquitto_sub -d -t $SYS/broker/clients/active
Client mosqsub/28715-ip-172-31 sending CONNECT
Client mosqsub/28715-ip-172-31 received CONNACK
Client mosqsub/28715-ip-172-31 sending SUBSCRIBE (Mid: 1, Topic: /broker/clients/active, QoS: 0)
Client mosqsub/28715-ip-172-31 received SUBACK
Subscribed (mid: 1): 0

配置文件中的sys_interval 为1,但我没有收到有关上述订阅的任何更新。我也尝试订阅一些替代主题,但仍然没有收到任何东西。 Mosquitto 服务器托管在具有 linux 操作系统的 AWS 微型实例上。

【问题讨论】:

    标签: publish-subscribe mqtt mosquitto


    【解决方案1】:

    $SYS 被您的 shell 解释为环境变量,并在蚊子子看到它之前被替换。您可以通过它在 SUBSCRIBE 日志语句中报告的主题字符串看到这已发生。

    您应该在主题字符串周围加上引号:

     $ mosquitto_sub -d -t '$SYS/broker/clients/active'
    

    【讨论】:

    • 这让我明白了。它需要单引号;我有双引号。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多