提交 9647d784 编写于 作者: 浅梦2013's avatar 浅梦2013

统一调整文档和示例

上级 dda0fa36
......@@ -51,7 +51,7 @@ public class MqttClientTest {
.username(username)
.password(password)
.clientId(clientId)
.connect();
.connectSync();
client.subQos0("/sys/" + productKey + '/' + deviceName + "/thing/event/property/post_reply", (context, topic, message, payload) -> {
System.out.println(topic + '\t' + new String(payload, StandardCharsets.UTF_8));
......
......@@ -37,7 +37,7 @@ public class DeviceA {
.port(1883)
.username("admin")
.password("123456")
.connect();
.connectSync();
client.subQos0("/a/door/open", (context, topic, message, payload) -> {
logger.info(topic + '\t' + new String(payload, StandardCharsets.UTF_8));
......
......@@ -37,7 +37,7 @@ public class DeviceB {
.port(1883)
.username("admin")
.password("123456")
.connect();
.connectSync();
client.subQos0("/a/door/open", (context, topic, message, payload) -> {
logger.info(topic + '\t' + new String(payload, StandardCharsets.UTF_8));
......
......@@ -36,7 +36,7 @@ public class DeviceC {
.port(1883)
.username("admin")
.password("123456")
.connect();
.connectSync();
Timer timer = new Timer();
timer.schedule(new TimerTask() {
......
......@@ -56,7 +56,8 @@ public class MqttClientTest {
.retain(false)
.qos(MqttQoS.AT_MOST_ONCE); // 遗嘱消息
})
.connect();
// 同步连接,也可以使用 connect() 异步(可以避免 broker 没启动照成启动卡住),但是下面的订阅和发布可能还没连接成功。
.connectSync();
client.subQos0("/test/123", new IMqttClientMessageListener() {
@Override
......
......@@ -51,7 +51,7 @@ public class MqttClientTest {
.password(password)
.clientId(clientId)
.useSsl()
.connect();
.connectSync();
// 订阅命令下发topic
String cmdRequestTopic = "$oc/devices/" + deviceId + "/sys/commands/#";
......
......@@ -58,7 +58,7 @@ MqttClient client = MqttClient.create()
}
})
.properties() // mqtt5 properties
.connect();
.connectSync(); // 同步连接,也可以使用 connect(),可以避免 broker 没启动照成启动卡住。
// 消息订阅,同类方法 subxxx
client.subQos0("/test/#", (context, topic, message, payload) -> {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册