Jelajahi Sumber

fixed 设备订阅主题实时更新
add 设备订阅主题列表接口

18339543638 4 tahun lalu
induk
melakukan
0ec487718d

+ 13 - 2
jetlinks-components/network-component/mqtt-component/src/main/java/org/jetlinks/community/network/mqtt/gateway/device/MqttServerDeviceGateway.java

@@ -197,6 +197,17 @@ class MqttServerDeviceGateway implements DeviceGateway, MonitorSupportDeviceGate
                             }
                             gatewayMonitor.disconnected();
                             gatewayMonitor.totalConnection(counter.sum());
+
+
+                            /**
+                             * 清空订阅主题
+                             */
+                            registry.getDevice(conn.getClientId())
+                                .doOnNext(operator -> {
+                                    operator.getTopics().clear();
+                                    eventBus.publish(String.format("/dashboard/device/%s/changed/topics",
+                                        conn.getClientId()),new TimeSyncMessage());
+                                }).subscribe();
                         });
                         return Tuples.of(connection.accept(), device, newSession);
                     } else {
@@ -217,7 +228,7 @@ class MqttServerDeviceGateway implements DeviceGateway, MonitorSupportDeviceGate
     }
     //处理已经建立连接的MQTT连接的主题订阅
     private void handleSubscriptionTopic(Tuple3<MqttConnection, DeviceOperator, MqttConnectionSession> tuple3) {
-         tuple3.getT1()
+        tuple3.getT1()
             .handleSubscribe(true)
             .doOnNext(topic->{
                 MqttSubscribeMessage message = topic.getMessage();
@@ -232,7 +243,7 @@ class MqttServerDeviceGateway implements DeviceGateway, MonitorSupportDeviceGate
 
     //取消MQTT连接的主题订阅
     private void handleUnSubscriptionTopic(Tuple3<MqttConnection, DeviceOperator, MqttConnectionSession> tuple3) {
-         tuple3.getT1()
+        tuple3.getT1()
             .handleUnSubscribe(true)
             .doOnNext(topic->{
                 MqttUnsubscribeMessage message = topic.getMessage();

+ 48 - 0
jetlinks-manager/device-manager/src/main/java/org/jetlinks/community/device/entity/DeviceShadowEntity.java

@@ -0,0 +1,48 @@
+package org.jetlinks.community.device.entity;
+
+/**
+ * @author lifang
+ * @version 1.0.0
+ * @ClassName DeviceShadowEntity.java
+ * @Description 设备影子
+ * @createTime 2021年10月14日 09:36:00
+ */
+public class DeviceShadowEntity {
+
+    /**
+     * 设备状态
+     */
+    private String state;
+
+    /**
+     * 元数据,仅限设备属性
+     */
+    private String metadata;
+
+
+    private String timestamp;
+    /**
+     * 校验数据格式
+     * @return
+     */
+    public boolean verify(){
+        return true;
+    }
+
+
+    /**
+     * 影子状态
+     */
+    public class ShadowState{
+
+
+    }
+
+    /**
+     * 影子元数据
+     */
+    public class ShadowMetadata{
+
+
+    }
+}

+ 9 - 0
jetlinks-manager/device-manager/src/main/java/org/jetlinks/community/device/web/DeviceInstanceController.java

@@ -613,6 +613,15 @@ public class DeviceInstanceController implements
             .as(response::writeWith);
     }
 
+
+    //获取设备订阅主题
+    @GetMapping("/{deviceId:.+}/sub/topics")
+    @Operation(summary = "获取设备订阅主题")
+    public Mono<Set<String>> getSubTopics(@PathVariable @Parameter(description = "设备ID") String deviceId) {
+        return registry.getDevice(deviceId)
+            .map(DeviceOperator::getTopics);
+    }
+
     //设置设备影子
     @PutMapping("/{deviceId:.+}/shadow")
     @SaveAction