package zutil.net.mqtt;

import zutil.log.CompactLogFormatter;
import zutil.log.LogUtil;

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.logging.Level;
import java.util.logging.Logger;

public class MqttBrokerRun implements MqttSubscriptionListener {
    private static final Logger logger = LogUtil.getLogger();

    public static void main(String[] args) throws IOException {
        LogUtil.setGlobalLevel(Level.FINEST);
        LogUtil.setGlobalFormatter(new CompactLogFormatter());

        MqttBroker mqttBroker = new MqttBroker();
        mqttBroker.addGlobalSubscriber(new MqttBrokerRun());
        mqttBroker.start();
    }

    @Override
    public void dataPublished(String topic, byte[] data) {
        logger.info("MQTT data published(topic: " + topic + "): " + new String(data, StandardCharsets.UTF_8));
    }
}
