Commit 831970233c63cd50f056b330f0e675102d2dd9c3
1 parent
7ab61b6d
【代码优化】IoT: 数据桥梁的执行器根据引入的消息队列动态加载
Showing
4 changed files
with
19 additions
and
0 deletions
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/rule/action/databridge/IotKafkaMQDataBridgeExecute.java
| @@ -6,6 +6,7 @@ import cn.iocoder.yudao.module.iot.mq.message.IotDeviceMessage; | @@ -6,6 +6,7 @@ import cn.iocoder.yudao.module.iot.mq.message.IotDeviceMessage; | ||
| 6 | import lombok.extern.slf4j.Slf4j; | 6 | import lombok.extern.slf4j.Slf4j; |
| 7 | import org.apache.kafka.clients.producer.ProducerConfig; | 7 | import org.apache.kafka.clients.producer.ProducerConfig; |
| 8 | import org.apache.kafka.common.serialization.StringSerializer; | 8 | import org.apache.kafka.common.serialization.StringSerializer; |
| 9 | +import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; | ||
| 9 | import org.springframework.kafka.core.DefaultKafkaProducerFactory; | 10 | import org.springframework.kafka.core.DefaultKafkaProducerFactory; |
| 10 | import org.springframework.kafka.core.KafkaTemplate; | 11 | import org.springframework.kafka.core.KafkaTemplate; |
| 11 | import org.springframework.stereotype.Component; | 12 | import org.springframework.stereotype.Component; |
| @@ -21,6 +22,7 @@ import java.util.concurrent.TimeUnit; | @@ -21,6 +22,7 @@ import java.util.concurrent.TimeUnit; | ||
| 21 | * | 22 | * |
| 22 | * @author HUIHUI | 23 | * @author HUIHUI |
| 23 | */ | 24 | */ |
| 25 | +@ConditionalOnClass(KafkaTemplate.class) | ||
| 24 | @Component | 26 | @Component |
| 25 | @Slf4j | 27 | @Slf4j |
| 26 | public class IotKafkaMQDataBridgeExecute extends | 28 | public class IotKafkaMQDataBridgeExecute extends |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/rule/action/databridge/IotRabbitMQDataBridgeExecute.java
| @@ -7,6 +7,7 @@ import com.rabbitmq.client.Channel; | @@ -7,6 +7,7 @@ import com.rabbitmq.client.Channel; | ||
| 7 | import com.rabbitmq.client.Connection; | 7 | import com.rabbitmq.client.Connection; |
| 8 | import com.rabbitmq.client.ConnectionFactory; | 8 | import com.rabbitmq.client.ConnectionFactory; |
| 9 | import lombok.extern.slf4j.Slf4j; | 9 | import lombok.extern.slf4j.Slf4j; |
| 10 | +import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; | ||
| 10 | import org.springframework.stereotype.Component; | 11 | import org.springframework.stereotype.Component; |
| 11 | 12 | ||
| 12 | import java.nio.charset.StandardCharsets; | 13 | import java.nio.charset.StandardCharsets; |
| @@ -17,6 +18,7 @@ import java.time.LocalDateTime; | @@ -17,6 +18,7 @@ import java.time.LocalDateTime; | ||
| 17 | * | 18 | * |
| 18 | * @author HUIHUI | 19 | * @author HUIHUI |
| 19 | */ | 20 | */ |
| 21 | +@ConditionalOnClass(Channel.class) | ||
| 20 | @Component | 22 | @Component |
| 21 | @Slf4j | 23 | @Slf4j |
| 22 | public class IotRabbitMQDataBridgeExecute extends | 24 | public class IotRabbitMQDataBridgeExecute extends |
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/rule/action/databridge/IotRocketMQDataBridgeExecute.java
| @@ -9,6 +9,7 @@ import org.apache.rocketmq.client.producer.SendResult; | @@ -9,6 +9,7 @@ import org.apache.rocketmq.client.producer.SendResult; | ||
| 9 | import org.apache.rocketmq.client.producer.SendStatus; | 9 | import org.apache.rocketmq.client.producer.SendStatus; |
| 10 | import org.apache.rocketmq.common.message.Message; | 10 | import org.apache.rocketmq.common.message.Message; |
| 11 | import org.apache.rocketmq.remoting.common.RemotingHelper; | 11 | import org.apache.rocketmq.remoting.common.RemotingHelper; |
| 12 | +import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; | ||
| 12 | import org.springframework.stereotype.Component; | 13 | import org.springframework.stereotype.Component; |
| 13 | 14 | ||
| 14 | import java.time.LocalDateTime; | 15 | import java.time.LocalDateTime; |
| @@ -18,6 +19,7 @@ import java.time.LocalDateTime; | @@ -18,6 +19,7 @@ import java.time.LocalDateTime; | ||
| 18 | * | 19 | * |
| 19 | * @author HUIHUI | 20 | * @author HUIHUI |
| 20 | */ | 21 | */ |
| 22 | +@ConditionalOnClass(DefaultMQProducer.class) | ||
| 21 | @Component | 23 | @Component |
| 22 | @Slf4j | 24 | @Slf4j |
| 23 | public class IotRocketMQDataBridgeExecute extends | 25 | public class IotRocketMQDataBridgeExecute extends |
yudao-server/pom.xml
| @@ -114,6 +114,19 @@ | @@ -114,6 +114,19 @@ | ||
| 114 | <artifactId>yudao-module-iot-biz</artifactId> | 114 | <artifactId>yudao-module-iot-biz</artifactId> |
| 115 | <version>${revision}</version> | 115 | <version>${revision}</version> |
| 116 | </dependency> | 116 | </dependency> |
| 117 | + <!-- IoT 数据桥梁的执行器所需消息队列。如果您只需要使用 rocketmq 那么则注释掉其它消息队列即可 --> | ||
| 118 | + <dependency> | ||
| 119 | + <groupId>org.apache.rocketmq</groupId> | ||
| 120 | + <artifactId>rocketmq-spring-boot-starter</artifactId> | ||
| 121 | + </dependency> | ||
| 122 | + <dependency> | ||
| 123 | + <groupId>org.springframework.kafka</groupId> | ||
| 124 | + <artifactId>spring-kafka</artifactId> | ||
| 125 | + </dependency> | ||
| 126 | + <dependency> | ||
| 127 | + <groupId>org.springframework.boot</groupId> | ||
| 128 | + <artifactId>spring-boot-starter-amqp</artifactId> | ||
| 129 | + </dependency> | ||
| 117 | 130 | ||
| 118 | <!-- spring boot 配置所需依赖 --> | 131 | <!-- spring boot 配置所需依赖 --> |
| 119 | <dependency> | 132 | <dependency> |