feat(设备接入网关): 修改MQTT服务网关时,重新加载网络组件 (#336)

* feat(基础模块): 增加通用导入工具

* feat(设备): 导入设备数据,并提供日志下载

* feat(设备接入网关): 修改MQTT服务网关时,重新加载网络组件
This commit is contained in:
Zhang Ji 2023-07-11 16:30:48 +08:00 committed by GitHub
parent 5271799511
commit a90d180fa4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 0 deletions

View File

@ -3,6 +3,7 @@ package org.jetlinks.community.network.mqtt.gateway.device;
import io.netty.handler.codec.mqtt.MqttConnectReturnCode;
import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.api.trace.StatusCode;
import lombok.Getter;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.jetlinks.community.gateway.AbstractDeviceGateway;
@ -69,6 +70,7 @@ class MqttServerDeviceGateway extends AbstractDeviceGateway {
private final DeviceSessionManager sessionManager;
//Mqtt 服务
@Getter
private final MqttServer mqttServer;
//解码后的设备消息处理器

View File

@ -16,6 +16,8 @@ import org.jetlinks.supports.server.DecodedClientMessageHandler;
import org.springframework.stereotype.Component;
import reactor.core.publisher.Mono;
import java.util.Objects;
@Component
public class MqttServerDeviceGatewayProvider implements DeviceGatewayProvider {
@ -79,4 +81,21 @@ public class MqttServerDeviceGatewayProvider implements DeviceGatewayProvider {
Mono.empty()
));
}
@Override
public Mono<? extends DeviceGateway> reloadDeviceGateway(DeviceGateway gateway,
DeviceGatewayProperties properties) {
MqttServerDeviceGateway deviceGateway = ((MqttServerDeviceGateway) gateway);
String networkId = properties.getChannelId();
//网络组件发生了变化
if (!Objects.equals(networkId, deviceGateway.getMqttServer().getId())) {
return gateway
.shutdown()
.then(this
.createDeviceGateway(properties)
.flatMap(gate -> gate.startup().thenReturn(gate)));
}
return Mono.just(gateway);
}
}