| | |
| | | |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.ResponseBody; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | |
| | | @RestController |
| | | public class MqttPubController { |
| | | |
| | | @Autowired |
| | | private MqttGatewayService gatewayService; |
| | | private MqttProviderConfig providerClient; |
| | | |
| | | |
| | | @RequestMapping("/hello") |
| | | public String hello() { |
| | | return "hello!"; |
| | | @RequestMapping("/sendMessage") |
| | | public @ResponseBody |
| | | String sendMessage(String topic, String message) { |
| | | try { |
| | | providerClient.publish(topic, message); |
| | | return "发送成功"; |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | return "发送失败"; |
| | | } |
| | | } |
| | | |
| | | @RequestMapping("/sendMqtt") |
| | | public String sendMqtt(String sendData) { |
| | | System.out.println(sendData); |
| | | System.out.println("进入sendMqtt-------" + sendData); |
| | | gatewayService.sendToMqtt("topic01", (String) sendData); |
| | | return "Test is OK"; |
| | | } |
| | | |
| | | @RequestMapping("/sendMqttTopic") |
| | | public String sendMqtt(String sendData, String topic) { |
| | | //System.out.println(sendData+" "+topic); |
| | | //System.out.println("进入inbound发送:"+sendData); |
| | | gatewayService.sendToMqtt(topic, (String) sendData); |
| | | return "Test is OK"; |
| | | } |
| | | |
| | | } |