Set the number of kafka consumers in Springboot

Onejae Lee
Mar 19, 2022

You can configure the number of kafka consumers by “setConsumerFactory” method when creating factory

@Bean
public ConcurrentKafkaListenerContainerFactory<String, Crawler>
crawlJobKafkaListenerContainerFactory() {
ConcurrentKafkaListenerContainerFactory<String, Crawler> factory
= new ConcurrentKafkaListenerContainerFactory<>();
factory.setConcurrency(3);
factory.setConsumerFactory(crawlJobConsumerFactory());
return factory;
}
# kafka-consumer-groups.sh — bootstrap-server localhost:9092 — describe — group job-group

Stay with the number of consumers not bigger than # of partitions.

--

--