使用发布者的 clienID 连接 MQTT 消息

Connect MQTT Message with clienID of Publisher

我想将 MQTT 数据存储在 MySQL 数据库中,并希望存储客户端 ID、主题和消息内容。

对于某些设备,我无法控制主题或消息语法,因此无法将客户端 ID 附加到消息或在主题中添加客户端 ID。

有没有可能做到这一点?

也许发布的消息可以自动创建一个带有客户端id的主题?

我看到 mosquitto 在 server.log 中记录了没有内容的客户端 ID,在客户端中记录了没有客户端 ID 的内容...是否可以 link 这些?

或者也许已经有可以执行此操作的 MQTT 代理?

如果有人能给我一些建议,那就太好了。

您的要求不符合规范 (Client Identifier is not included in messages delivered to subscribers it only "identifies the Client to the Server"). As such I'd be surprised if a broker supported this; however for brokers that allow you hook into the publish flow (e.g. verne),将您想要的信息转储到数据库应该相对容易(或者,如果 QOS+1,您可以挂接到商店代码) .

如果您想将信息(客户端 ID)作为消息的一部分传递,那么您可能需要研究使用 MQTT v5 for delivery. v5 includes support for properties,它提供了一种无需触及发布即可向消息添加额外数据的方法有效负载。