Skip to content

Commit 0dd1e47

Browse files
wenyanshi-123shiwenyan
andauthored
Add a note regarding client_id in the MQTT documentation. (#833)
Co-authored-by: shiwenyan <wenyan.shi@timecho.com>
1 parent 27b3586 commit 0dd1e47

4 files changed

Lines changed: 52 additions & 2 deletions

File tree

src/UserGuide/Master/Table/API/Programming-MQTT.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,4 +230,16 @@ Then, in your server:
230230
5. Now IoTDB will use your implementation to parse the MQTT message.
231231

232232
More: the message format can be anything you want. For example, if it is a binary format,
233-
just use `payload.forEachByte()` or `payload.array` to get bytes content.
233+
just use `payload.forEachByte()` or `payload.array` to get bytes content.
234+
235+
## 7. Caution
236+
237+
To avoid compatibility issues caused by a default client_id, always explicitly supply a unique, non-empty client_id in every MQTT client.
238+
Behavior varies when the client_id is missing or empty. Common examples:
239+
1. Explicitly sending an empty string
240+
• MQTTX: When client_id="", IoTDB silently discards the message.
241+
• mosquitto_pub: When client_id="", IoTDB receives the message normally.
242+
2. Omitting client_id entirely
243+
• MQTTX: IoTDB accepts the message.
244+
• mosquitto_pub: IoTDB rejects the connection.
245+
Therefore, explicitly assigning a unique, non-empty client_id is the simplest way to eliminate these discrepancies and ensure reliable message delivery.

src/UserGuide/Master/Tree/API/Programming-MQTT.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,5 +178,15 @@ Then, in your server:
178178
More: the message format can be anything you want. For example, if it is a binary format,
179179
just use `payload.forEachByte()` or `payload.array` to get bytes content.
180180

181-
181+
## 6. Caution
182+
183+
To avoid compatibility issues caused by a default client_id, always explicitly supply a unique, non-empty client_id in every MQTT client.
184+
Behavior varies when the client_id is missing or empty. Common examples:
185+
1. Explicitly sending an empty string
186+
• MQTTX: When client_id="", IoTDB silently discards the message.
187+
• mosquitto_pub: When client_id="", IoTDB receives the message normally.
188+
2. Omitting client_id entirely
189+
• MQTTX: IoTDB accepts the message.
190+
• mosquitto_pub: IoTDB rejects the connection.
191+
Therefore, explicitly assigning a unique, non-empty client_id is the simplest way to eliminate these discrepancies and ensure reliable message delivery.
182192

src/zh/UserGuide/Master/Table/API/Programming-MQTT.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,3 +232,18 @@ public class CustomizedLinePayloadFormatter implements PayloadFormatter {
232232

233233
More: MQTT 协议的消息不限于 line,你还可以用任意二进制。通过如下函数获得:
234234
`payload.forEachByte()` or `payload.array`
235+
236+
## 7. 注意事项
237+
238+
为避免因缺省client_id引发的兼容性问题,强烈建议在所有MQTT客户端中始终显式地提供唯一且非空的 client_id。
239+
不同客户端在client_id缺失或为空时的表现并不一致,常见示例如下:
240+
1. 显式传入空字符串
241+
• MQTTX:client_id=""时,IoTDB会直接丢弃消息;
242+
• mosquitto_pub:client_id=""时,IoTDB能正常接收消息。
243+
2. 完全不传client_id
244+
• MQTTX:消息可被IoTDB正常接收;
245+
• mosquitto_pub:IoTDB拒绝连接。
246+
由此可见,显式指定唯一且非空的client_id是消除上述差异、确保消息可靠投递的最简单做法。
247+
248+
249+

src/zh/UserGuide/Master/Tree/API/Programming-MQTT.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,3 +176,16 @@ public class CustomizedJsonPayloadFormatter implements PayloadFormatter {
176176

177177
More: MQTT 协议的消息不限于 json,你还可以用任意二进制。通过如下函数获得:
178178
`payload.forEachByte()` or `payload.array`
179+
180+
181+
## 6. 注意事项
182+
183+
为避免因缺省client_id引发的兼容性问题,强烈建议在所有MQTT客户端中始终显式地提供唯一且非空的 client_id。
184+
不同客户端在client_id缺失或为空时的表现并不一致,常见示例如下:
185+
1. 显式传入空字符串
186+
• MQTTX:client_id=""时,IoTDB会直接丢弃消息;
187+
• mosquitto_pub:client_id=""时,IoTDB能正常接收消息。
188+
2. 完全不传client_id
189+
• MQTTX:消息可被IoTDB正常接收;
190+
• mosquitto_pub:IoTDB拒绝连接。
191+
由此可见,显式指定唯一且非空的client_id是消除上述差异、确保消息可靠投递的最简单做法。

0 commit comments

Comments
 (0)