实现MQTT协议的中间件,目前使用的是Apache-Apollo服务器。
本文使用Gateway绑定的方式,进行消息发送。
SpringBoot
使用idea
新建Spring Initializr
工程,过程省略,使用Maven
对项目依赖进行管理,配置过程省略。
完成后,在pom
文件中加入以下依赖
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-integration</artifactId> </dependency> <dependency> <groupId>org.springframework.integration</groupId> <artifactId>spring-integration-stream</artifactId> </dependency> <dependency> <groupId>org.springframework.integration</groupId> <artifactId>spring-integration-mqtt</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency>
|
然后配置SpringBoot的文件application.yml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| spring: mqtt: publish: username: admin password: password url: tcp://127.0.0.1:61613 client: id: mqttId default: topic: topic
|