设备通过mqtt协议传送数据包到服务器,但是现在处理数据是通过kafka,所以就整合了camel转发
maven
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-mqtt</artifactId>
<version>2.23.1</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-spring-boot</artifactId>
<version>2.16.0</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-core</artifactId>
<version>2.23.1</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-kafka</artifactId>
<version>2.19.2</version>
</dependency>
springboot的版本是 2.0.4.RELEASE
camel配置文件
data.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://camel.apache.org/schema/spring
http://camel.apache.org/schema/spring/camel-spring.xsd">
<camelContext id="testCamelContext" xmlns="http://camel.apache.org/schema/spring">
<route autoStartup="true">
<from uri="mqtt:adv?host=tcp://ip:1883&userName=smx&password=smx&subscribeTopicNames=test/#"/>
<to uri="kafka:topicName?brokers=127.0.0.1:9092&clientId=16" />
</route>
</camelContext>
</beans>
由于是springboot项目,所以加载其他的配置文件还得扫描,新增加一个类
@Configuration
@ImportResource(locations= {"classpath:data.xml"})
public class Config {
}