MQ currently supports clients to connect and consume data using MQTT, and only supports TLS encryption. Standard MQTT v3.1.1 is supported by default.
Connection Protocol | Certificate | Address | Port |
---|---|---|---|
MQTT | Certificate Download | IPv4: 47.52.102.24 | 11006 |
A third-party SDK is recommended. Please visit https://github.com/mqtt/mqtt.github.io/wiki/libraries
The consumer development process is as follows:
The client is connected to the server by sending a MQTT CONNECT message that consists of three elements, as follows:
Parameter | Required or not | Description |
---|---|---|
clientId | No | A user-defined valid UTF-8 string, which is nullable |
username | Yes | Please indicate instance name |
password | Yes | Please specify the token, and seeAccess Authentication for algorithms where: res=mqs/$ instance name. |
In addition, there are some limitations on the use of keepalive, will and session fields in a CONNNECT message, as follows:
Function | Supported or Not | Description |
---|---|---|
keepalive | Supported | Scope of support: 30~4,800s |
will | Not Supported | will and will retain flags must be set to 0, and will qos must be set to 0 |
session | Not Supported | clean session flag must be set to 1 |
Subscribe Message
In a Subscribe message, topic has the following format, where wildcards are not supported.
$sys/pb/consume/$instance name/$TOPIC/$SUB
When you create a subscription, request QoS must be set to be greater than 0, otherwise the subscription fails.
Subscribe Acknowledged Message
A subscription is acknowledged using a MQTT SubAck message, and it returns 0x01 (fixed) if successful.
Request QoS | SubAck Return Code | Description |
---|---|---|
0 | 0x80 | Subscribe failed |
1 | 0x01 | Subscribe succeeded, with maximum QoS set to 1 |
2 | 0x01 | Subscribe succeeded, with maximum QoS set to 1 |
Unsubscribe Message
The client cancels a subscription using a MQTT Unsubscribe message.
Unsubscribe Acknowledgement Message
The server acknowledges the cancellation using a MQTT UnsubAck message.
After receiving the publish message, the client parses its payload segments according to the MQTT protocol, and then parses payload data content, following the steps below.
Download link: https://github.com/protocolbuffers/protobuf/releases
onenet-mq.proto interface file is as follows:
syntax = "proto3";
package mq;
message Msg{
uint64 msgid = 1; //MQ中该消息的真实id
bytes data = 2; //具体的数据
uint64 timestamp = 3; //精确到ms
}
Save onenet-mq.protofile locally
Compile the file by language, taking Java as an example.
protoc --java_out=$DST_DIR $SRC_DIR/onenet-mq.proto
Taking Java as an example, compile and generate an OnenetMq.java file, and add this source file to a project.
An example of Java is as follows:
OnenetMq.Msg obj;
obj = OnenetMq.Msg.parseFrom(mqttPayload);
System.out.println(obj.getMsgid());
System.out.println(new String(obj.getData().toByteArray()));
System.out.println(obj.getTimestamp());