package zd.common.mqtt.config;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 消费者例子 ， 需要订阅请参考
 * @Author: zhoupan
 * @Date: 2021/11/15/14:42
 * @Description:
 */

public class ConsumerMqtt {

    Logger logger = LoggerFactory.getLogger(ConsumerMqtt.class);

//    @Autowired
//    private MqttProperties mqttProperties;
//    @Bean
//    @ServiceActivator(inputChannel = "mqttInputChannel")
//    public MessageHandler handler() {
//        return message -> logger.info("收到消息："+ message.getPayload());
//    }

//    @Bean
//    public MessageProducer inbound(MqttPahoClientFactory mqttPahoClientFactory) {
//        String[] inboundTopics = mqttProperties.getTopics().split(",");
//        if(inboundTopics==null||inboundTopics.length==0) return null;
//
//
//        MqttPahoMessageDrivenChannelAdapter adapter =
//                new MqttPahoMessageDrivenChannelAdapter(mqttProperties.getConsumerClientId(),
//                        mqttPahoClientFactory,inboundTopics);
//        adapter.setCompletionTimeout(5000);
//        adapter.setConverter(new DefaultPahoMessageConverter());
//        adapter.setQos(1);
//        adapter.setOutputChannel(mqttInputChannel());
//        return adapter;
//    }

}
