package com.mortals.xhx.queue.provider;

import com.mortals.xhx.queue.TbQueueConsumer;
import com.mortals.xhx.queue.TbQueueMsg;
import com.mortals.xhx.queue.TbQueueProducer;
import com.mortals.xhx.queue.kafka.TbKafkaConsumerTemplate;
import com.mortals.xhx.queue.kafka.TbKafkaProducerTemplate;
import com.mortals.xhx.queue.kafka.TbKafkaSettings;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * kafka 消息工厂类
 *
 * @author: zxfei
 * @date: 2021/11/22 15:00
 */
@Component
@ConditionalOnExpression("'${queue.type:null}'=='kafka'")
public class KafkaTbCoreQueueFactory implements TbCoreQueueFactory {

    @Autowired
    private TbKafkaSettings kafkaSettings;

    /**
     * 初始化创建消息生产者
     *
     * @return
     */
    @Override
    public TbQueueProducer<TbQueueMsg> createMsgProducer() {
        TbKafkaProducerTemplate.TbKafkaProducerTemplateBuilder<TbQueueMsg> builder = TbKafkaProducerTemplate.builder();
        builder.settings(kafkaSettings);
        return builder.build();
    }

    /**
     * 初始化创建消息消费者
     *
     * @return
     */
    @Override
    public TbQueueConsumer<TbQueueMsg> createMsgConsumer() {
        TbKafkaConsumerTemplate.TbKafkaConsumerTemplateBuilder<TbQueueMsg> comsumerBuilder = TbKafkaConsumerTemplate.builder();
        comsumerBuilder.settings(kafkaSettings);
        return comsumerBuilder.build();
    }

    @Override
    public List<TbQueueConsumer<TbQueueMsg>> createListMsgConsumer(List<String> vhosts) {
        return null;
    }
}
