|
@@ -10,12 +10,12 @@
|
|
package cc.iotkit.test.mqtt.service;
|
|
package cc.iotkit.test.mqtt.service;
|
|
|
|
|
|
|
|
|
|
-import cc.iotkit.common.utils.JsonUtils;
|
|
|
|
import cc.iotkit.test.mqtt.model.Request;
|
|
import cc.iotkit.test.mqtt.model.Request;
|
|
import cc.iotkit.test.mqtt.model.Response;
|
|
import cc.iotkit.test.mqtt.model.Response;
|
|
import io.netty.handler.codec.mqtt.MqttQoS;
|
|
import io.netty.handler.codec.mqtt.MqttQoS;
|
|
import io.vertx.core.Handler;
|
|
import io.vertx.core.Handler;
|
|
import io.vertx.core.buffer.Buffer;
|
|
import io.vertx.core.buffer.Buffer;
|
|
|
|
+import io.vertx.core.json.Json;
|
|
import io.vertx.mqtt.MqttClient;
|
|
import io.vertx.mqtt.MqttClient;
|
|
import io.vertx.mqtt.messages.MqttPublishMessage;
|
|
import io.vertx.mqtt.messages.MqttPublishMessage;
|
|
import lombok.Data;
|
|
import lombok.Data;
|
|
@@ -53,7 +53,7 @@ public class MessageHandler implements Handler<MqttPublishMessage> {
|
|
log.info("received msg,topic:{},payload:{}", topic, payload);
|
|
log.info("received msg,topic:{},payload:{}", topic, payload);
|
|
|
|
|
|
if (topic.endsWith("register_reply")) {
|
|
if (topic.endsWith("register_reply")) {
|
|
- Response response = JsonUtils.parseObject(payload, Response.class);
|
|
|
|
|
|
+ Response response = Json.decodeValue(payload, Response.class);
|
|
//子设备注册成功
|
|
//子设备注册成功
|
|
if (response.getCode() == 0) {
|
|
if (response.getCode() == 0) {
|
|
Map<String, Object> data = response.getData();
|
|
Map<String, Object> data = response.getData();
|
|
@@ -78,18 +78,18 @@ public class MessageHandler implements Handler<MqttPublishMessage> {
|
|
if (topic.endsWith("_reply")) {
|
|
if (topic.endsWith("_reply")) {
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
- Request request = JsonUtils.parseObject(payload, Request.class);
|
|
|
|
|
|
+ Request request = Json.decodeValue(payload, Request.class);
|
|
|
|
|
|
Response response = new Response(request.getId(), 0, new HashMap<>());
|
|
Response response = new Response(request.getId(), 0, new HashMap<>());
|
|
client.publish(topic.replace("/c/", "/s/") + "_reply",
|
|
client.publish(topic.replace("/c/", "/s/") + "_reply",
|
|
- Buffer.buffer(JsonUtils.toJsonString(response)), MqttQoS.AT_LEAST_ONCE, false, false);
|
|
|
|
|
|
+ Buffer.buffer(Json.encode(response)), MqttQoS.AT_LEAST_ONCE, false, false);
|
|
|
|
|
|
//属性设置后上报属性
|
|
//属性设置后上报属性
|
|
String setTopic = "/c/service/property/set";
|
|
String setTopic = "/c/service/property/set";
|
|
if (topic.endsWith(setTopic)) {
|
|
if (topic.endsWith(setTopic)) {
|
|
request.setId(UUID.randomUUID().toString());
|
|
request.setId(UUID.randomUUID().toString());
|
|
client.publish(topic.replace(setTopic, "/s/event/property/post"),
|
|
client.publish(topic.replace(setTopic, "/s/event/property/post"),
|
|
- Buffer.buffer(JsonUtils.toJsonString(request)), MqttQoS.AT_LEAST_ONCE, false, false);
|
|
|
|
|
|
+ Buffer.buffer(Json.encode(request)), MqttQoS.AT_LEAST_ONCE, false, false);
|
|
}
|
|
}
|
|
} catch (Throwable e) {
|
|
} catch (Throwable e) {
|
|
log.info("receive msg error", e);
|
|
log.info("receive msg error", e);
|