package com.qiuguo.iot.user.api.config;

import org.springframework.amqp.rabbit.connection.ConnectionFactory;

import org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.amqp.rabbit.config.SimpleRabbitListenerContainerFactory;


/**
 * @author simon
 * @date 2023/9/26
 * @description
 **/
@Configuration
public class TopicRabbitListenerConfig {
   @Bean
   public SimpleRabbitListenerContainerFactory simpleRabbitListenerContainerFactory(ConnectionFactory connectionFactory) {
      // 配置消息监听容器工厂
      SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory();
      factory.setConnectionFactory(connectionFactory);
      factory.setConcurrentConsumers(3); // 并发消费者数量
      factory.setMaxConcurrentConsumers(10); // 最大并发消费者数量
      factory.setPrefetchCount(1); // 每个消费者的消息预取数量
      return factory;
   }
}
