doum
6 天以前 5e59a6a3b10c0990f494b5a20e1102fd79b0db1b
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
32
33
34
35
36
37
38
39
40
41
42
43
package com.doumee.service.business.impl.mqtt;
 
import com.alibaba.fastjson.JSONObject;
import com.doumee.mqtt.config.MqttConfig;
import com.doumee.mqtt.service.MqttBizService;
import com.doumee.mqtt.service.MqttToolService;
import lombok.extern.slf4j.Slf4j;
import org.eclipse.paho.client.mqttv3.MqttClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
 *  与硬件对接服务
 * @author 江蹄蹄
 * @date 2023/10/09 18:06
 */
@Service
@Slf4j
public class MqttSubServiceImpl implements MqttBizService {
    @Autowired
    private MqttPushCallback callBack ;
    @Override
    public MqttClient subscribe(MqttClient client,MqttConfig config,String[] topics){
        log.error("mqtt订阅开始========开始"+ JSONObject.toJSONString(config));
        client = MqttToolService.subscribe(client,config, topics,callBack);
        log.error("mqtt订阅开始========结束"+ JSONObject.toJSONString(config));
        return client;
    }
    @Override
    public MqttClient unsubscribe(MqttClient client,MqttConfig config,String[] topics){
        log.error("mqtt订阅开始========开始"+ JSONObject.toJSONString(config));
        client = MqttToolService.unsubscribe(client,config, topics,callBack);
        log.error("mqtt订阅开始========结束"+ JSONObject.toJSONString(config));
        return client;
    }
 
    @Override
    public MqttClient publish(MqttClient client,MqttConfig config, String topic, String param){
        log.error("mqtt发布消息========开始"+ JSONObject.toJSONString(config)+"\n"+param);
        client = MqttToolService.pubMessage(client,config,param,topic,callBack);
        log.error("mqtt发布消息========结束"+ JSONObject.toJSONString(config));
        return client;
    }
}