Last Updated on : 2021-10-21 10:19:21download
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;
Note: 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/Configure a test device.
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 it will be sent to the test channel for you to debug device functions.
On the tool IntelliJ IDEA, right-click the ConsumerExample.java file and select Run to run the program.
Control the device with a mobile app.
Automatically get the push messages on IntelliJ IDEA.
For more information about message types, see Message Types.
Parameter name | Data type | Description |
---|---|---|
protocol | Integer | The protocol number. |
pv | String | The version number of the communication protocol. |
t | Long | The timestamp. |
sign | String | The signature. |
data | String | The data body. |
{
"protocol": 4,
"pv": "2.0",
"t": 146052438362,
"data":"4FDEE3FE59Fxxxx***",
"sign": "58285279b5b5790c7d917dxxxxx***"
}
Is this page helpful?
YesFeedbackIs this page helpful?
YesFeedback