package net.northking.cctp.debuger.config;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.core.AcknowledgeMode;
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
import org.springframework.amqp.rabbit.core.RabbitAdmin;
import org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitMQConfig {
    private static final Logger logger = LoggerFactory.getLogger(RabbitMQConfig.class);
    @Bean
    public SimpleMessageListenerContainer messageContainer(ConnectionFactory connectionFactory){
        logger.info("Creating messageContainer");
        SimpleMessageListenerContainer messageContainer = new SimpleMessageListenerContainer(connectionFactory);
        messageContainer.setAutoDeclare(true);
        //设置是否重回队列
        messageContainer.setDefaultRequeueRejected(false);
        //自动签收
        messageContainer.setAcknowledgeMode(AcknowledgeMode.AUTO);
        logger.info("MessageContainer created.");
        return messageContainer;
    }
    @Bean
    public RabbitAdmin rabbitAdmin(ConnectionFactory connectionFactory){
        logger.info("Creating rabbitAdmin");
        RabbitAdmin rabbitAdmin = new RabbitAdmin(connectionFactory);
        logger.info("RabbitAdmin created.");
        return  rabbitAdmin;
    }


}
