Warm tip: This article is reproduced from stackoverflow.com, please click
apache-kafka spring-boot spring-kafka kafka-consumer-api

How to increase the Kafka consumers in Spring

发布于 2020-03-27 10:28:35

I am creating a Spring Boot application with Kafka support. I have created a Producer and a Consumer and everything is working like a charm. In runtime I have one consumer. I wanted to have many consumers, the same number of partitions of my topic.

How to create many consumers?

I have been searching in documentation but with no success.

Thank you !

Questioner
Nebrass Lamouchi
Viewed
85
victor gallet 2019-07-03 23:26

You need to create a ConcurrentKafkaListenerContainerFactory and set the concurrency parameter. It creates 1 or more KafkaMessageListenerContainers based on concurrency. If the ContainerProperties is configured with TopicPartitions, the TopicPartitions are distributed evenly across the instances.

For example

ConcurrentKafkaListenerContainerFactory<String, String> factory = new ConcurrentKafkaListenerContainerFactory<>();
factory.setConcurrency(12);