package com.zd.forward.serivce.mqtt;

import com.alibaba.fastjson.JSON;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Service;
import zd.common.mqtt.config.MessageBody;

/**
 * 公用发送类
 * @Author: zhoupan
 * @Date: 2021/10/08/10:42
 * @Description:
 */
@Service
@ConditionalOnProperty(prefix = "sys.mqtt" ,name = "outbound",havingValue = "true",matchIfMissing = true)
public class CommonSend {

    @Autowired
    MqttProducer mqttProducer;


    /**
     * 发送消息：去重模式
     * @param topic
     * @param messageBody
     */
    public  void  send(String topic, MessageBody messageBody)
    {
        mqttProducer.sendToMqtt(topic, 2, JSON.toJSONString(messageBody));
    }

    /**
     * 发送消息
     * @param topic
     * @param messageBody
     * @param QOS
     */
    public  void  send(String topic,MessageBody messageBody,int QOS)
    {
        mqttProducer.sendToMqtt(topic, QOS, JSON.toJSONString(messageBody));
    }



}
