package com.njzscloud.common.mqtt.util;

import cn.hutool.extra.spring.SpringUtil;
import com.njzscloud.common.mqtt.support.Mqtt;
import com.njzscloud.common.mqtt.support.MqttMsg;

import java.util.function.Consumer;

public final class MqttUtil {
    private static final Mqtt mqtt;

    static {
        mqtt = SpringUtil.getBean(Mqtt.class);
    }

    public static void subscribe(String topic, int qos, Consumer<MqttMsg> handler) {
        mqtt.subscribe(topic, qos, handler);
    }

    public static void subscribe(String topic, Consumer<MqttMsg> handler) {
        mqtt.subscribe(topic, handler);
    }

    public static void subscribe(String topic, int qos) {
        mqtt.subscribe(topic, qos);
    }

    public static void subscribe(String topic) {
        mqtt.subscribe(topic);
    }


    public static void publish(String topic, Object msg) {
        mqtt.publish(topic, msg);
    }

    public static void publish(String topic, int qos, Object msg) {
        mqtt.publish(topic, qos, msg);
    }
}
