package cn.iododer.yudao.module.mqtt.controller;

import cn.iododer.yudao.module.mqtt.util.MqttUtils;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@Tag(name = "MQTT通讯")
@RestController
@RequestMapping("/mqtt")
@Validated
@Slf4j
public class MqttController {

    @Autowired
    private MqttUtils mqttUtils;


    @PostMapping("/pub")
    public String pub(String topic, String msg) {
        try {
            mqttUtils.pub( topic, msg);
            return "发送成功！";
        } catch (Exception e) {
            log.error("消息发送失败！", e);
        }
        return "发送成功！";
    }


}
