package com.muyu.mqtt;

import lombok.extern.log4j.Log4j2;
import org.eclipse.paho.client.mqttv3.MqttClient;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 消费处理器 MsgHandler
 *
 * @author Yangle
 * Date 2024/6/6 15:15
 */
@Log4j2
@Component
public class MsgHandler {
    @Autowired
    private MqttFactory mqttFactory;
    @RabbitListener(queues = "ip")
    public void msg(String msg){
        log.info("接收到消息：{}",msg);

        String[] split = msg.split(",");

        for (String s : split) {
            MqttProperties mqttProperties = MqttProperties.configBuild(
                    s,
                    "test1"
            );
            log.error("接收到消息初始化信息:{}",mqttProperties);
            MqttClient mqttClient = mqttFactory.creatClient(mqttProperties);
            log.error("client创建成功:{}",mqttClient.getClientId());
        }


    }


}
