发布/订阅/取消订阅

发布消息

API 定义:

  1. POST api/v3/mqtt/publish

请求参数:

  1. {
  2. "topic": "test_topic",
  3. "payload": "hello",
  4. "qos": 1,
  5. "retain": false,
  6. "client_id": "mqttjs_ab9069449e"
  7. }

请求示例:

  1. POST api/v3/mqtt/publish

返回数据:

  1. {
  2. "code": 0
  3. }

创建订阅

API 定义:

  1. POST api/v3/mqtt/subscribe

请求参数:

  1. {
  2. "topic": "test_topic",
  3. "qos": 1,
  4. "client_id": "mqttjs_ab9069449e"
  5. }

请求示例:

  1. POST api/v3/mqtt/subscribe

返回数据:

  1. {
  2. "code": 0
  3. }

取消订阅

API 定义:

  1. POST api/v3/mqtt/unsubscribe

请求参数:

  1. {
  2. "topic": "test_topic",
  3. "client_id": "mqttjs_ab9069449e"
  4. }

请求示例:

  1. POST api/v3/mqtt/unsubscribe

返回数据:

  1. {
  2. "code": 0
  3. }

批量发布消息

API 定义:

  1. POST api/v3/mqtt/publish_batch

请求参数:

  1. [{
  2. "topic": "test_topic1",
  3. "payload": "hello1",
  4. "qos": 1,
  5. "retain": false,
  6. "client_id": "mqttjs_1"
  7. },{
  8. "topic": "test_topic2",
  9. "payload": "hello2",
  10. "qos": 1,
  11. "retain": false,
  12. "client_id": "mqttjs_2"
  13. }]

请求示例:

  1. POST api/v3/mqtt/publish_batch

返回数据:

  1. {
  2. "code": 0,
  3. "data": [
  4. {
  5. "topic": "test_topic1",
  6. "code": 0
  7. },
  8. {
  9. "topic": "test_topic2",
  10. "code": 0
  11. }
  12. ]
  13. }

批量创建订阅

API 定义:

  1. POST api/v3/mqtt/subscribe_batch

请求参数:

  1. [{
  2. "topic": "test_topic1",
  3. "qos": 1,
  4. "client_id": "mqttjs_1"
  5. },{
  6. "topic": "test_topic2",
  7. "qos": 1,
  8. "client_id": "mqttjs_2"
  9. }]

请求示例:

  1. POST api/v3/mqtt/subscribe_batch

返回数据:

  1. {
  2. "code": 0,
  3. "data": [
  4. {
  5. "client_id": "mqttjs_1",
  6. "topic": "test_topic1",
  7. "code": 0
  8. },
  9. {
  10. "client_id": "mqttjs_2",
  11. "topic": "test_topic2",
  12. "code": 0
  13. }
  14. ]
  15. }

批量取消订阅

API 定义:

  1. POST api/v3/mqtt/unsubscribe_batch

请求参数:

  1. [{
  2. "topic": "test_topic1",
  3. "client_id": "mqttjs_1"
  4. },{
  5. "topic": "test_topic2",
  6. "client_id": "mqttjs_2"
  7. }]

请求示例:

  1. POST api/v3/mqtt/unsubscribe_batch

返回数据:

  1. {
  2. "code": 0,
  3. "data": [
  4. {
  5. "client_id": "mqttjs_1",
  6. "topic": "test_topic1",
  7. "code": 0
  8. },
  9. {
  10. "client_id": "mqttjs_2",
  11. "topic": "test_topic2",
  12. "code": 0
  13. }
  14. ]
  15. }