feat(设备接入网关): 修改MQTT服务网关时,重新加载网络组件 (#336)
* feat(基础模块): 增加通用导入工具 * feat(设备): 导入设备数据,并提供日志下载 * feat(设备接入网关): 修改MQTT服务网关时,重新加载网络组件
This commit is contained in:
parent
5271799511
commit
a90d180fa4
|
|
@ -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;
|
||||
|
||||
//解码后的设备消息处理器
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue