jiazx0107@163.com
2023-11-08 a31a452b9999ba3c811c36b5cb1b3ec0c18d037d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package com.fzzy.mqtt;
 
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
 
@RestController
public class MqttPubController {
 
    @Autowired
    private MqttGatewayService gatewayService;
 
 
    @RequestMapping("/hello")
    public String hello() {
        return "hello!";
    }
 
    @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";
    }
 
}