Commit 551b0435 by 罗志长

feat: 心跳

parent f163c0d8
package org.jetlinks.protocol.official;
import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.SneakyThrows;
import org.hswebframework.web.bean.FastBeanCopier;
......@@ -21,10 +22,8 @@ import org.reactivestreams.Publisher;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import java.util.Arrays;
import java.util.Collections;
import java.util.Optional;
import java.util.StringJoiner;
import java.nio.charset.StandardCharsets;
import java.util.*;
import java.util.function.Function;
public enum TopicMessageCodec {
......@@ -282,6 +281,22 @@ public enum TopicMessageCodec {
//状态检查
stateCheck("/*/state-check", DeviceStateCheckMessage.class),
stateCheckReply("/*/state-check/reply", DeviceStateCheckMessageReply.class),
//心跳
heartbeat("/*/heartbeat", DeviceLogMessage.class) {
@Override
Publisher<DeviceMessage> doDecode(ObjectMapper mapper, String[] topic, byte[] payload) {
JSONObject jsonObject = JSONObject.parseObject(new String(payload, StandardCharsets.UTF_8));
JSONObject properties = jsonObject.getJSONObject("payload");
DeviceLogMessage msg = new DeviceLogMessage();
Map<String, Object> content = new HashMap<>();
content.put("deviceId", topic[1]);
content.put("messageType", "HEARTBEAT");
content.put("properties", properties.getInnerMap());
content.put("timestamp", msg.getTimestamp());
msg.setLog(JSONObject.toJSONString(content));
return Mono.just(msg);
}
},
;
TopicMessageCodec(String topic,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment