Search code examples
spring-bootrabbitmqspring-amqpspring-rabbit

How many consumers can i have? (Spring-boot + RabbitMq)


I'm using Spring Boot with RabbitMq, and a question came up, is there a limited number of consumers I can create? Where do I find this value?


Solution

  • Spring-Amqp has no limit for consumer number.

    But usually it will be restricted by other things. For example, if you use SimpleMessageListner, one consumer corresponds to one thread. When your number of consumers is large, your app may not be able to create so many threads, resulting in OOM: unable to create new native thread.

        // OOM in my computer
        @RabbitListener(queues = "testq", concurrency = "10000-10000")
        public void listen() {
        }
    

    If you use a CachingConnectionFactory(connections), set CacheMode to CONNECTION, maybe your rabbitmq server cannot carry a very large number of consumers (probably hit the maximum number of file descriptors.), and your app may not be able to connect to rabbitmq.