# mqtt-spring-boot-starter-example **Repository Path**: deane163/mqtt-spring-boot-starter-example ## Basic Information - **Project Name**: mqtt-spring-boot-starter-example - **Description**: No description available - **Primary Language**: Java - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2020-03-03 - **Last Updated**: 2020-12-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # mqtt-spring-boot-starter-example #### 介绍 示例, 介绍如何快速集成 mqtt-spring-boot-starter, #### application.yml ``` server: port: 8888 servlet: context-path: /example spring: mqtt: url: tcp://127.0.0.1:1883 userName: admin password: 123456 inbound: clientId: iot-thinker-inbound topics: /test/123456 outbound: clientId: iot-thinker-outbound topics: /test/123456 ``` #### MqttController ··· @RestController @RequestMapping(value = "/mqtt") @Slf4j public class MQTTController { @Autowired private MqttGateway mqttGateway; @RequestMapping(value = "/send") public String sendMessage(){ log.info("send Message ..."); mqttGateway.sendToMqtt("The test Message".getBytes(),"/test/123456"); return "success"; } } ··· #### 参与贡献 ··· @Component(value = "messageHandler") public class ReceiveMessagehandler implements MessageHandler { @Override public void handleMessage(Message message) { System.out.println("MyMessageHandler ====> 收到订阅消息: ==>" + message); String topic = message.getHeaders().get("mqtt_receivedTopic").toString(); System.out.println("MyMessageHandler ====> 消息主题:==>" + topic); Object payLoad = message.getPayload(); // 如果不设置转换器这里强转byte[]会报错 byte[] data = (byte[]) payLoad; System.out.println("MyMessageHandler====> Message is : ==> " + new String(data)); } } ··· #### 码云特技 1. 使用 Readme\_XXX.md 来支持不同的语言,例如 Readme\_en.md, Readme\_zh.md 2. 码云官方博客 [blog.gitee.com](https://blog.gitee.com) 3. 你可以 [https://gitee.com/explore](https://gitee.com/explore) 这个地址来了解码云上的优秀开源项目 4. [GVP](https://gitee.com/gvp) 全称是码云最有价值开源项目,是码云综合评定出的优秀开源项目 5. 码云官方提供的使用手册 [https://gitee.com/help](https://gitee.com/help) 6. 码云封面人物是一档用来展示码云会员风采的栏目 [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/)