ConcurrentKafkaListenerContainerFactory creates the listener containers behind methods annotated with @KafkaListener. A listener container wraps a KafkaConsumer, subscribes it to the declared topic or topics, and delivers records to a message-handling POJO method. Spring Boot can create the factory automatically when Kafka support is enabled, while an application can supply its own factory when default behavior is insufficient. section 12.2.1 section 12.2.2
Its key throughput control is concurrency. With one listener consumer handling an input topic's partitions, increasing partitions alone does not create a consumer per partition. Setting factory concurrency to the configured partition count creates a KafkaConsumer per partition, supporting maximum throughput for that topic. section 12.2.2
Configure a factory for partition-level consumption
Define a ConcurrentKafkaListenerContainerFactory bean, attach the application's ConsumerFactory, and call setConcurrency(partitions). Naming the bean method kafkaListenerContainerFactory replaces the default factory expected by the container. Alternatively, name a factory explicitly and select it from @KafkaListener with containerFactory = "custom-container". section 12.2.2 section 12.2.2
This factory is part of a larger listener flow: @KafkaListener supplies the topic and consumer group, the container consumes records, the handler processes a LoanApplication, and KafkaTemplate can send the processed record to an approved, rejected, or quality-assurance topic. Property placeholders keep topics and group IDs configurable without recompilation. section 12.2.1 section 12.2.1
Listing 12.11 Increasing the concurrency level for a container listener factory
@Bean
public ConcurrentKafkaListenerContainerFactory<String, LoanApplication>
kafkaListenerContainerFactory() { #1
ConcurrentKafkaListenerContainerFactory<String, LoanApplication>
kafkaListenerContainerFactory =
new ConcurrentKafkaListenerContainerFactory<>();
kafkaListenerContainerFactory.setConsumerFactory(consumerFactory());
kafkaListenerContainerFactory.setConcurrency(partitions); #2
return kafkaListenerContainerFactory;
}
The configuration shows the complete minimal customization: construct the factory, provide its ConsumerFactory, and align concurrency with the partition count. section 12.2.2
