diff --git a/jetlinks-components/gateway-component/src/main/java/org/jetlinks/community/gateway/supports/DefaultDeviceGatewayManager.java b/jetlinks-components/gateway-component/src/main/java/org/jetlinks/community/gateway/supports/DefaultDeviceGatewayManager.java index 2bbc87d1..ae1c78bf 100755 --- a/jetlinks-components/gateway-component/src/main/java/org/jetlinks/community/gateway/supports/DefaultDeviceGatewayManager.java +++ b/jetlinks-components/gateway-component/src/main/java/org/jetlinks/community/gateway/supports/DefaultDeviceGatewayManager.java @@ -123,14 +123,29 @@ public class DefaultDeviceGatewayManager implements DeviceGatewayManager { .compute(gatewayId, (id, gateway) -> { if (gateway != null) { log.debug("reload device gateway {} {}:{}", prop.getName(), prop.getProvider(), prop.getId()); - return provider + Mono reloaded = provider .reloadDeviceGateway(gateway, prop) .cast(DeviceGateway.class); + // 如果网关被禁用,重载后不启动 + if (!prop.isEnabled()) { + return reloaded.flatMap(g -> { + log.debug("device gateway {} is disabled, skip startup", gatewayId); + return Mono.just(g); + }); + } + return reloaded; } log.debug("create device gateway {} {}:{}", prop.getName(), prop.getProvider(), prop.getId()); - return provider + Mono created = provider .createDeviceGateway(prop) - .flatMap(newer -> newer.startup().thenReturn(newer)); + .cast(DeviceGateway.class); + // 只有启用的网关才自动启动 + if (prop.isEnabled()) { + return created.flatMap(newer -> newer.startup().thenReturn(newer)); + } else { + log.debug("device gateway {} is disabled, skip startup", gatewayId); + return created; + } }); }) .then(); diff --git a/jetlinks-components/plugin-component/src/main/java/org/jetlinks/community/plugin/device/PluginDeviceGatewayProvider.java b/jetlinks-components/plugin-component/src/main/java/org/jetlinks/community/plugin/device/PluginDeviceGatewayProvider.java index fbd54340..ce4c949b 100644 --- a/jetlinks-components/plugin-component/src/main/java/org/jetlinks/community/plugin/device/PluginDeviceGatewayProvider.java +++ b/jetlinks-components/plugin-component/src/main/java/org/jetlinks/community/plugin/device/PluginDeviceGatewayProvider.java @@ -17,6 +17,15 @@ package org.jetlinks.community.plugin.device; import org.hswebframework.web.exception.BusinessException; import org.hswebframework.web.i18n.LocaleUtils; +import org.jetlinks.community.PropertyConstants; +import org.jetlinks.community.codec.Serializers; +import org.jetlinks.community.gateway.DeviceGateway; +import org.jetlinks.community.gateway.supports.DeviceGatewayProperties; +import org.jetlinks.community.gateway.supports.DeviceGatewayProvider; +import org.jetlinks.community.plugin.PluginDriverManager; +import org.jetlinks.community.plugin.context.*; +import org.jetlinks.community.plugin.monitor.PluginMonitorHelper; +import org.jetlinks.community.plugin.utils.PluginUtils; import org.jetlinks.core.defaults.CompositeProtocolSupport; import org.jetlinks.core.device.DeviceOperator; import org.jetlinks.core.device.DeviceRegistry; @@ -36,15 +45,6 @@ import org.jetlinks.plugin.core.ServiceRegistry; import org.jetlinks.plugin.internal.PluginDataIdMapper; import org.jetlinks.plugin.internal.device.DeviceGatewayPlugin; import org.jetlinks.plugin.internal.device.PluginDeviceGatewayService; -import org.jetlinks.community.PropertyConstants; -import org.jetlinks.community.codec.Serializers; -import org.jetlinks.community.gateway.DeviceGateway; -import org.jetlinks.community.gateway.supports.DeviceGatewayProperties; -import org.jetlinks.community.gateway.supports.DeviceGatewayProvider; -import org.jetlinks.community.plugin.PluginDriverManager; -import org.jetlinks.community.plugin.context.*; -import org.jetlinks.community.plugin.monitor.PluginMonitorHelper; -import org.jetlinks.community.plugin.utils.PluginUtils; import org.reactivestreams.Publisher; import reactor.core.publisher.Mono; @@ -235,7 +235,14 @@ public class PluginDeviceGatewayProvider extends CompositeProtocolSupport .unwrap(PluginDeviceGateway.class) .shutdown() .then(createDeviceGateway(properties)) - .flatMap(gate -> gate.startup().thenReturn(gate)); + .flatMap(gate -> { + // 只有启用的网关才自动启动 + if (properties.isEnabled()) { + return gate.startup().thenReturn(gate); + } else { + return Mono.just(gate); + } + }); } @Override