Last Updated on : 2021-11-16 09:08:13download
A cloud project provides the message subscription feature. If the device status in the project changes, such as registration, data reporting, and offline events, Message Service is used to actively push event data to external partners with Pulsar. This helps to implement real-time and persistent messages.
Currently, Tuya Smart Message Service is customized and modified based on open-source Pulsar. The Pulsar SDK for Java is provided.
In this topic, the Java development tool IntelliJ IDEA is used to receive messages.
Click Pulsar SDK to enter the download page, click Code, download the package to the local computer, and then decompress the package.
Use IntelliJ IDEA to open the source code project. Click Open to find the downloaded and decompressed file in the previous step.
Modify parameters in open-mq-sdk/src/main/java/com.tuya.open.sdk/mq/MqConsumer.java. Modify the Java project as a test environment.
private MqEnv env = MqEnv.TEST;
MqEnv.TEST represents the test environment. MqEnv.PROD represents the formal environment. For more information about the parameters, see mq/MqEnv.java.
Modify parameters in open-mq-sdk/src/main/java/com.tuya.open.sdk/example/ConsumerExample.java.
String url = MqConfigs.CN_SERVER_URL;
String accessId = "xt*****ff**n1****8ufo";
String accessKey = "479bcb7345******582d9c******4ef7";
The parameters are described as follows.
accessId
: Enter the value of Access ID in the Authorization Key section.accessKey
: Enter the value of Access Secret in the Authorization Key section.url
: Select an option for the area where the API operation is called. For more information about the parameters, see mq/MqConfigs.java.
CN_SERVER_URL
(China): pulsar+ssl://mqe.tuyacn.com:7285/US_SERVER_URL
(America): pulsar+ssl://mqe.tuyaus.com:7285/EU_SERVER_URL
(Europe): pulsar+ssl://mqe.tuyaeu.com:7285/IND_SERVER_URL
(India): pulsar+ssl://mqe.tuyain.com:7285/On the page of Message Service, after your subscription is ready, Subscribed appears in the Status column. Click the Message Test tab.
Enter the associated device ID in the search box, click the magnifier icon, and then double-click the selected device.
If an associated device is set as a test device, the message reported by the device will be sent through the test channel for you to debug device functions.
Received message
Message received: {
"data": "mT9eqNz5MCgibKjEC+zsikNpoukkmad6K/uS18FozRETIriMEApJBXXm5o37QmMFzQtf9wFhkSQ6IBE2P3yYPrgKoKYnbLa+mN1TUCda/JYJWG9dqUPOlAUjyey1/PKjWu8doYvgN8fCe0HIMZBTI1eVfe4RzVkEHvaaFLVF+lpfqGdvTWhlLNbh6092SG9MsR8Aq2sXHt2naIfIT36xYU9xPHy0C65K3HDuQgwi69fRWhXdA1LWvsKPavTOappD",
"protocol": 4,
"pv": "2.0",
"sign": "d6be290bd0ffa196c313ecd315e6ff72",
"t": 1622701486365
}, seq = 0, time = 1622701486373, consumed time = 1622701486652
The following parameters are concatenated:
Parsed message data
the real message data: {
"dataId": "642769b3-c434-11eb-87b5-02425b0322e7",
"devId": "vdevo162201920765824",
"productKey": "atxdggtv9ddjt8xx",
"status": [{
"code": "switch_led",
"t": 1622701486258,
"value": true,
"20": "true"
}]
}
For more information about the data parsing method, see Sign. The data decryption method has been encapsulated in the SDK. For more information, see mq.AESBase64Utils.java.
Received message
Message received: {
"data": "UoHAZ1lTSAZRr0HFrePEw/rsMDlKAOIDeSjFQbf35K4TIriMEApJBXXm5o37QmMFzQtf9wFhkSQ6IBE2P3yYPrgKoKYnbLa+mN1TUCda/JYJWG9dqUPOlAUjyey1/PKjWu8doYvgN8fCe0HIMZBTI1eVfe4RzVkEHvaaFLVF+loWkfytt13z5nHmD9EPdmOZOxGcbyvjGOOp9iQOA3Om2XPur4DMxX0M+V+fFkyD9OXFRR9d0DA6J4LHmvDBtfO3U4HBd5MyELCdYJR7B+jCuVAcflFEGZKfv+5vINIuDZu0q1Ono+G6AcEyfmhIjrrY8EpmfMW/mWvfgGAreIOThH5WroVQpgbzIDgcGsXAsW1zzZYe27YlWKXleLLBEBcQx6Y2gSutLqfsu0MA59GNtg==",
"protocol": 4,
"pv": "2.0",
"sign": "f055d71c2caae3549a53adddde16aaec",
"t": 1622701494099
}, seq = 1, time = 1622701494099, consumed time = 1622701494059
Parsed message data
the real message data: {
"dataId": "68ce83d2-c434-11eb-87b5-02425b0322e7",
"devId": "vdevo162201920765824",
"productKey": "atxdggtv9ddjt8xx",
"status": [{
"code": "control_data",
"t": 1622701494064,
"28": "100b00193020800000000",
"value": "{\"bright\":0,
\"change_mode\":\"gradient\",
\"h\":176,
\"s\":403,
\"temperature\":0,
\"v\":520
}"
}]
}
Is this page helpful?
YesFeedbackIs this page helpful?
YesFeedback