OneNET IoT Platform Platform Introduction Introduction Manual Guidline for Device Development Guideline for Application Development
Other Service Common Question

Message Queue-MQ Consumer End Development Manual

Consumption Protocal

Message Queue-MQ currently supports clients to use MQTT protocol to connect and consume data, and only supports TLS encryption

Connection Protocal Certificate Address Port
MQTT Certificate Download ... 443

Client Connection

After the Message Queue service is enabled, OneNET assigns it a unique Id, as the figure below, used for one of the client connection authentication parameters.


Client can establish a connection with MQ by sending an MQTT connect message, the ways to write its three elements are as follows:

Parameter Required Parameter Description
username Yes write MQ_ID
password Yes write token, for algorithm, see [Security Authentication] (/book/easy-manual/
Where: res=mqs/$MQ_ID
clientId No User-defined legal UTF-8 string, can be empty

Subscription Message

  • Subscription message

     The topic format in the Subscribe Message is as follows, ** wildcards are not supported**

    $sys/pb/consume/$MQ_ID/$TOPIC/$SUB Request QoS must be greater than 0 when subscribing, otherwise subscription fails

  • Subscription message confirmation

    The platform uses the MQTT SubAck message to confirm the subscription. When return success, the return code fixed to 0x01

Request QoS SubAck return code Description
0 0x80 Subscription fails
1 0x01 Subscription success, maximum QoS is 1
2 0x01 Subscription success, maximum QoS is 1


  • When subscription success, MQ will actively push to client in the publish message form, according to genetation messages
  • The pushed message pushed by MQ during consumption will only be QoS = 1
  • After the client consumes the data, the puback message is used to reply to MQ in the order of data obtained
  • The format of data consumed when subscription succeeds refers to the Msg of the onenet-mq.proto file, as follows

Cancel subscription

  • Client uses the MQTT Unsubscribe message to cancel the subscription
  • Service end uses the MQTT UnsubAck message to make subscription cancellation confirmation

Data Parsing

step1 Install protobuf

step2 Download the following .proto file

Onenet-mq.proto interface file:

syntax = "proto3";

package mq;

message Msg{
    uint64 msgid          = 1; //real id of the message in MQ
    bytes data            = 2; //specific data


Save.proto file to local, e.g.: named as onenet-mq.proto

step2 Compile proto file

Compile the file according to the language, take Java as an example

protoc --java_out=$DST_DIR $SRC_DIR/onenet-mq.proto

step3 Add the compiled source file to the project

step4 Read data

  • Create Msg obj
  • Call obj.ParseFromString(payload) to parse data
  • Call to get message data
  • Call obj.msgid() to get message id

results matching ""

    No results matching ""