有什么办法可以将所有收到的消息存储在 MQTT 客户端?

Is there any way that I can store all the recieved messages at MQTT client side?

我在 PC 上使用 运行 Mosquitto 代理。

我在同一台电脑上打开了两个命令提示符 windows。从第一个 window 开始,我使用此命令发布了主题名称 'Hello' 的消息 "First_Message"。

mosquitto_pub -d -t Hello -m "First_Message"

从另一个命令 window,订阅同一主题使用:

mosquitto_sub -d -t Hello

然后我能够看到 "First_Message" 在命令 window 中接收并打印出来。

现在,我真正需要的不是在该命令中打印此消息 window,有什么方法可以将收到的消息存储在同一台 PC 上的文本文件中。

只需使用常规 shell 约定将输出通过管道传输到文件即可。

moquitto_sub -t Hello > log_file.txt

如果要将主题名称作为有效负载的前缀,请使用 -v 命令行参数。应该没有必要使用 -d 选项

moquitto_sub -v -t Hello > log_file.txt