订阅mosquitto broker的任何主题

时间:2016-06-16 15:44:13

标签: mosquitto

我正在使用mosquitto broker来订阅从机器到我的机器的消息。无论主题如何,我都希望收到所有消息。为此,我使用以下命令

mosquitto_sub -t \#

当然它接收所有主题的消息。但是当我输入命令并按下输入时,我看到的第一件事就是0.那是什么,为什么是0?为了您的信息,我的机器有ubuntu 14.04作为操作系统。我只想要发布的消息,没有像0那样的默认值。我怎么能这样做?

1 个答案:

答案 0 :(得分:1)

这看起来像是保留的消息。 要获取相关主题,可以使用-v arg:

运行mosquitto_sub
mosquitto_sub -t \# -v

要清除保留的消息,您必须发送空保留消息(-n和-r args)

mosquitto_pub -r -n -t *topic*

如果您只想要新消息,可以使用-R arg:

   -R
        If this argument is given, messages that are received that have the retain
        bit set will not be printed. Messages with retain set are "stale",
        in that it is not known when they were originally published. When
        subscribing to a wildcard topic there may be a large number of 
        retained messages. This argument suppresses their display.
 mosquitto_sub -t \# -v -R