zxl
2026-03-25 0b39edb68acc67ed01fbfe5d31bfa776a1b17de1
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
package com.tievd.jyz.mqtt.command;
 
import com.tievd.jyz.constants.SystemConstant;
import com.tievd.jyz.mqtt.MqttMsgSender;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
 
/**
 * Mqtt命令执行者
 * 
 * @author Wang
 *
 */
@Slf4j
@Component
public class MqttCommandReceiver {
 
    @Autowired
    private MqttMsgSender mqttMsgSender;
 
    public int send(String data,String topic) {
        try {
            mqttMsgSender.sendToMqtt(data,topic);
        } catch (Exception e) {
            log.error("Mqtt请求出错", e.getMessage());
            return SystemConstant.DEAL_FAIL;
        }
        return SystemConstant.DEAL_OK;
    }
}