jiazx0107@163.com
2023-11-08 768308ab47041062d9e97745099784acf297286b
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
package com.fzzy.mqtt;
 
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 MqttProviderConfig providerClient;
 
 
    @RequestMapping("/sendMessage")
    public @ResponseBody
    String sendMessage(String topic, String message) {
        try {
            providerClient.publish(topic, message);
            return "发送成功";
        } catch (Exception e) {
            e.printStackTrace();
            return "发送失败";
        }
    }
}