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 "发送失败"; } } }