From 0a8ef890592a9c0389c42daeebb9a3f0974c37e6 Mon Sep 17 00:00:00 2001
From: jiazx0107@163.com <jiazx0107@163.com>
Date: 星期三, 08 十一月 2023 14:59:41 +0800
Subject: [PATCH] 调整MQTT配置

---
 src/main/java/com/fzzy/mqtt/MqttPubController.java |   33 ++++++++++++---------------------
 1 files changed, 12 insertions(+), 21 deletions(-)

diff --git a/src/main/java/com/fzzy/mqtt/MqttPubController.java b/src/main/java/com/fzzy/mqtt/MqttPubController.java
index 644928d..c03b424 100644
--- a/src/main/java/com/fzzy/mqtt/MqttPubController.java
+++ b/src/main/java/com/fzzy/mqtt/MqttPubController.java
@@ -2,34 +2,25 @@
 
 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";
-    }
-
 }

--
Gitblit v1.9.3