如何使用spring在rabbitMQ中避免过多的连接(TCP)

时间:2017-06-01 07:26:02

标签: spring spring-boot tcp rabbitmq

问:当消息(30,000+)涌入时,消费者服务器建立了太多的TCP,甚至超过10,000。如果要避免这种情况,请在春季进行调整?!

监听器: enter image description here

sendMQ enter image description here

以下是rabbitmq.xml enter image description here

1 个答案:

答案 0 :(得分:0)

此stackoverflow问题可能有所帮助:How is concurrency in Spring AMQP Listener Container implemented?

快速摘录,请参阅并发':

<rabbit:listener-container
        connection-factory="myConnectionFactory"
        acknowledge="none"
        concurrency="10"
        requeue-rejected="false">
    <rabbit:listener ref="myListener" queues="myQueue"/>
</rabbit:listener-container>

我没有使用Spring XML配置,而是使用注释,但这是我用来限制并发使用者数量的原因:

@Bean
    public SimpleRabbitListenerContainerFactory rabbitListenerContainerFactory() {
        SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory();
        factory.setConnectionFactory(connectionFactory());

        // process each message one at a time
        factory.setConcurrentConsumers(1);
        factory.setMaxConcurrentConsumers(1);
        return factory;
    }