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 | 21 | import cn.iocoder.yudao.module.iot.gateway.service.device.message.IotDeviceMessageService; |
| 22 | 22 | import io.vertx.core.Vertx; |
| 23 | 23 | import lombok.extern.slf4j.Slf4j; |
| 24 | +import org.springframework.beans.factory.annotation.Qualifier; | |
| 24 | 25 | import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; |
| 25 | 26 | import org.springframework.boot.context.properties.EnableConfigurationProperties; |
| 26 | 27 | import org.springframework.context.annotation.Bean; |
| ... | ... | @@ -59,20 +60,20 @@ public class IotGatewayConfiguration { |
| 59 | 60 | @Slf4j |
| 60 | 61 | public static class EmqxProtocolConfiguration { |
| 61 | 62 | |
| 62 | - @Bean(destroyMethod = "close") | |
| 63 | + @Bean(name = "emqxVertx", destroyMethod = "close") | |
| 63 | 64 | public Vertx emqxVertx() { |
| 64 | 65 | return Vertx.vertx(); |
| 65 | 66 | } |
| 66 | 67 | |
| 67 | 68 | @Bean |
| 68 | 69 | public IotEmqxAuthEventProtocol iotEmqxAuthEventProtocol(IotGatewayProperties gatewayProperties, |
| 69 | - Vertx emqxVertx) { | |
| 70 | + @Qualifier("emqxVertx") Vertx emqxVertx) { | |
| 70 | 71 | return new IotEmqxAuthEventProtocol(gatewayProperties.getProtocol().getEmqx(), emqxVertx); |
| 71 | 72 | } |
| 72 | 73 | |
| 73 | 74 | @Bean |
| 74 | 75 | public IotEmqxUpstreamProtocol iotEmqxUpstreamProtocol(IotGatewayProperties gatewayProperties, |
| 75 | - Vertx emqxVertx) { | |
| 76 | + @Qualifier("emqxVertx") Vertx emqxVertx) { | |
| 76 | 77 | return new IotEmqxUpstreamProtocol(gatewayProperties.getProtocol().getEmqx(), emqxVertx); |
| 77 | 78 | } |
| 78 | 79 | |
| ... | ... | @@ -91,7 +92,7 @@ public class IotGatewayConfiguration { |
| 91 | 92 | @Slf4j |
| 92 | 93 | public static class TcpProtocolConfiguration { |
| 93 | 94 | |
| 94 | - @Bean(destroyMethod = "close") | |
| 95 | + @Bean(name = "tcpVertx", destroyMethod = "close") | |
| 95 | 96 | public Vertx tcpVertx() { |
| 96 | 97 | return Vertx.vertx(); |
| 97 | 98 | } |
| ... | ... | @@ -101,7 +102,7 @@ public class IotGatewayConfiguration { |
| 101 | 102 | IotDeviceService deviceService, |
| 102 | 103 | IotDeviceMessageService messageService, |
| 103 | 104 | IotTcpConnectionManager connectionManager, |
| 104 | - Vertx tcpVertx) { | |
| 105 | + @Qualifier("tcpVertx") Vertx tcpVertx) { | |
| 105 | 106 | return new IotTcpUpstreamProtocol(gatewayProperties.getProtocol().getTcp(), |
| 106 | 107 | deviceService, messageService, connectionManager, tcpVertx); |
| 107 | 108 | } |
| ... | ... | @@ -126,7 +127,7 @@ public class IotGatewayConfiguration { |
| 126 | 127 | @Slf4j |
| 127 | 128 | public static class MqttProtocolConfiguration { |
| 128 | 129 | |
| 129 | - @Bean(destroyMethod = "close") | |
| 130 | + @Bean(name = "mqttVertx", destroyMethod = "close") | |
| 130 | 131 | public Vertx mqttVertx() { |
| 131 | 132 | return Vertx.vertx(); |
| 132 | 133 | } |
| ... | ... | @@ -135,7 +136,7 @@ public class IotGatewayConfiguration { |
| 135 | 136 | public IotMqttUpstreamProtocol iotMqttUpstreamProtocol(IotGatewayProperties gatewayProperties, |
| 136 | 137 | IotDeviceMessageService messageService, |
| 137 | 138 | IotMqttConnectionManager connectionManager, |
| 138 | - Vertx mqttVertx) { | |
| 139 | + @Qualifier("mqttVertx") Vertx mqttVertx) { | |
| 139 | 140 | return new IotMqttUpstreamProtocol(gatewayProperties.getProtocol().getMqtt(), messageService, |
| 140 | 141 | connectionManager, mqttVertx); |
| 141 | 142 | } |
| ... | ... | @@ -163,7 +164,7 @@ public class IotGatewayConfiguration { |
| 163 | 164 | @Slf4j |
| 164 | 165 | public static class MqttWsProtocolConfiguration { |
| 165 | 166 | |
| 166 | - @Bean(destroyMethod = "close") | |
| 167 | + @Bean(name = "mqttWsVertx", destroyMethod = "close") | |
| 167 | 168 | public Vertx mqttWsVertx() { |
| 168 | 169 | return Vertx.vertx(); |
| 169 | 170 | } |
| ... | ... | @@ -172,7 +173,7 @@ public class IotGatewayConfiguration { |
| 172 | 173 | public IotMqttWsUpstreamProtocol iotMqttWsUpstreamProtocol(IotGatewayProperties gatewayProperties, |
| 173 | 174 | IotDeviceMessageService messageService, |
| 174 | 175 | IotMqttWsConnectionManager connectionManager, |
| 175 | - Vertx mqttWsVertx) { | |
| 176 | + @Qualifier("mqttWsVertx") Vertx mqttWsVertx) { | |
| 176 | 177 | return new IotMqttWsUpstreamProtocol(gatewayProperties.getProtocol().getMqttWs(), |
| 177 | 178 | messageService, connectionManager, mqttWsVertx); |
| 178 | 179 | } | ... | ... |