Commit a7f655e1e7ba87bca575246fc543dd20247b0123
1 parent
908f9587
fix:【iot】修复当多个协议同时启用时,出现 Bean 冲突的问题
Showing
1 changed file
with
10 additions
and
9 deletions
yudao-module-iot/yudao-module-iot-gateway/src/main/java/cn/iocoder/yudao/module/iot/gateway/config/IotGatewayConfiguration.java
| @@ -21,6 +21,7 @@ import cn.iocoder.yudao.module.iot.gateway.service.device.IotDeviceService; | @@ -21,6 +21,7 @@ import cn.iocoder.yudao.module.iot.gateway.service.device.IotDeviceService; | ||
| 21 | import cn.iocoder.yudao.module.iot.gateway.service.device.message.IotDeviceMessageService; | 21 | import cn.iocoder.yudao.module.iot.gateway.service.device.message.IotDeviceMessageService; |
| 22 | import io.vertx.core.Vertx; | 22 | import io.vertx.core.Vertx; |
| 23 | import lombok.extern.slf4j.Slf4j; | 23 | import lombok.extern.slf4j.Slf4j; |
| 24 | +import org.springframework.beans.factory.annotation.Qualifier; | ||
| 24 | import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; | 25 | import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; |
| 25 | import org.springframework.boot.context.properties.EnableConfigurationProperties; | 26 | import org.springframework.boot.context.properties.EnableConfigurationProperties; |
| 26 | import org.springframework.context.annotation.Bean; | 27 | import org.springframework.context.annotation.Bean; |
| @@ -59,20 +60,20 @@ public class IotGatewayConfiguration { | @@ -59,20 +60,20 @@ public class IotGatewayConfiguration { | ||
| 59 | @Slf4j | 60 | @Slf4j |
| 60 | public static class EmqxProtocolConfiguration { | 61 | public static class EmqxProtocolConfiguration { |
| 61 | 62 | ||
| 62 | - @Bean(destroyMethod = "close") | 63 | + @Bean(name = "emqxVertx", destroyMethod = "close") |
| 63 | public Vertx emqxVertx() { | 64 | public Vertx emqxVertx() { |
| 64 | return Vertx.vertx(); | 65 | return Vertx.vertx(); |
| 65 | } | 66 | } |
| 66 | 67 | ||
| 67 | @Bean | 68 | @Bean |
| 68 | public IotEmqxAuthEventProtocol iotEmqxAuthEventProtocol(IotGatewayProperties gatewayProperties, | 69 | public IotEmqxAuthEventProtocol iotEmqxAuthEventProtocol(IotGatewayProperties gatewayProperties, |
| 69 | - Vertx emqxVertx) { | 70 | + @Qualifier("emqxVertx") Vertx emqxVertx) { |
| 70 | return new IotEmqxAuthEventProtocol(gatewayProperties.getProtocol().getEmqx(), emqxVertx); | 71 | return new IotEmqxAuthEventProtocol(gatewayProperties.getProtocol().getEmqx(), emqxVertx); |
| 71 | } | 72 | } |
| 72 | 73 | ||
| 73 | @Bean | 74 | @Bean |
| 74 | public IotEmqxUpstreamProtocol iotEmqxUpstreamProtocol(IotGatewayProperties gatewayProperties, | 75 | public IotEmqxUpstreamProtocol iotEmqxUpstreamProtocol(IotGatewayProperties gatewayProperties, |
| 75 | - Vertx emqxVertx) { | 76 | + @Qualifier("emqxVertx") Vertx emqxVertx) { |
| 76 | return new IotEmqxUpstreamProtocol(gatewayProperties.getProtocol().getEmqx(), emqxVertx); | 77 | return new IotEmqxUpstreamProtocol(gatewayProperties.getProtocol().getEmqx(), emqxVertx); |
| 77 | } | 78 | } |
| 78 | 79 | ||
| @@ -91,7 +92,7 @@ public class IotGatewayConfiguration { | @@ -91,7 +92,7 @@ public class IotGatewayConfiguration { | ||
| 91 | @Slf4j | 92 | @Slf4j |
| 92 | public static class TcpProtocolConfiguration { | 93 | public static class TcpProtocolConfiguration { |
| 93 | 94 | ||
| 94 | - @Bean(destroyMethod = "close") | 95 | + @Bean(name = "tcpVertx", destroyMethod = "close") |
| 95 | public Vertx tcpVertx() { | 96 | public Vertx tcpVertx() { |
| 96 | return Vertx.vertx(); | 97 | return Vertx.vertx(); |
| 97 | } | 98 | } |
| @@ -101,7 +102,7 @@ public class IotGatewayConfiguration { | @@ -101,7 +102,7 @@ public class IotGatewayConfiguration { | ||
| 101 | IotDeviceService deviceService, | 102 | IotDeviceService deviceService, |
| 102 | IotDeviceMessageService messageService, | 103 | IotDeviceMessageService messageService, |
| 103 | IotTcpConnectionManager connectionManager, | 104 | IotTcpConnectionManager connectionManager, |
| 104 | - Vertx tcpVertx) { | 105 | + @Qualifier("tcpVertx") Vertx tcpVertx) { |
| 105 | return new IotTcpUpstreamProtocol(gatewayProperties.getProtocol().getTcp(), | 106 | return new IotTcpUpstreamProtocol(gatewayProperties.getProtocol().getTcp(), |
| 106 | deviceService, messageService, connectionManager, tcpVertx); | 107 | deviceService, messageService, connectionManager, tcpVertx); |
| 107 | } | 108 | } |
| @@ -126,7 +127,7 @@ public class IotGatewayConfiguration { | @@ -126,7 +127,7 @@ public class IotGatewayConfiguration { | ||
| 126 | @Slf4j | 127 | @Slf4j |
| 127 | public static class MqttProtocolConfiguration { | 128 | public static class MqttProtocolConfiguration { |
| 128 | 129 | ||
| 129 | - @Bean(destroyMethod = "close") | 130 | + @Bean(name = "mqttVertx", destroyMethod = "close") |
| 130 | public Vertx mqttVertx() { | 131 | public Vertx mqttVertx() { |
| 131 | return Vertx.vertx(); | 132 | return Vertx.vertx(); |
| 132 | } | 133 | } |
| @@ -135,7 +136,7 @@ public class IotGatewayConfiguration { | @@ -135,7 +136,7 @@ public class IotGatewayConfiguration { | ||
| 135 | public IotMqttUpstreamProtocol iotMqttUpstreamProtocol(IotGatewayProperties gatewayProperties, | 136 | public IotMqttUpstreamProtocol iotMqttUpstreamProtocol(IotGatewayProperties gatewayProperties, |
| 136 | IotDeviceMessageService messageService, | 137 | IotDeviceMessageService messageService, |
| 137 | IotMqttConnectionManager connectionManager, | 138 | IotMqttConnectionManager connectionManager, |
| 138 | - Vertx mqttVertx) { | 139 | + @Qualifier("mqttVertx") Vertx mqttVertx) { |
| 139 | return new IotMqttUpstreamProtocol(gatewayProperties.getProtocol().getMqtt(), messageService, | 140 | return new IotMqttUpstreamProtocol(gatewayProperties.getProtocol().getMqtt(), messageService, |
| 140 | connectionManager, mqttVertx); | 141 | connectionManager, mqttVertx); |
| 141 | } | 142 | } |
| @@ -163,7 +164,7 @@ public class IotGatewayConfiguration { | @@ -163,7 +164,7 @@ public class IotGatewayConfiguration { | ||
| 163 | @Slf4j | 164 | @Slf4j |
| 164 | public static class MqttWsProtocolConfiguration { | 165 | public static class MqttWsProtocolConfiguration { |
| 165 | 166 | ||
| 166 | - @Bean(destroyMethod = "close") | 167 | + @Bean(name = "mqttWsVertx", destroyMethod = "close") |
| 167 | public Vertx mqttWsVertx() { | 168 | public Vertx mqttWsVertx() { |
| 168 | return Vertx.vertx(); | 169 | return Vertx.vertx(); |
| 169 | } | 170 | } |
| @@ -172,7 +173,7 @@ public class IotGatewayConfiguration { | @@ -172,7 +173,7 @@ public class IotGatewayConfiguration { | ||
| 172 | public IotMqttWsUpstreamProtocol iotMqttWsUpstreamProtocol(IotGatewayProperties gatewayProperties, | 173 | public IotMqttWsUpstreamProtocol iotMqttWsUpstreamProtocol(IotGatewayProperties gatewayProperties, |
| 173 | IotDeviceMessageService messageService, | 174 | IotDeviceMessageService messageService, |
| 174 | IotMqttWsConnectionManager connectionManager, | 175 | IotMqttWsConnectionManager connectionManager, |
| 175 | - Vertx mqttWsVertx) { | 176 | + @Qualifier("mqttWsVertx") Vertx mqttWsVertx) { |
| 176 | return new IotMqttWsUpstreamProtocol(gatewayProperties.getProtocol().getMqttWs(), | 177 | return new IotMqttWsUpstreamProtocol(gatewayProperties.getProtocol().getMqttWs(), |
| 177 | messageService, connectionManager, mqttWsVertx); | 178 | messageService, connectionManager, mqttWsVertx); |
| 178 | } | 179 | } |