Consider the following code-
@Bean
public ConsumerFactory<String, String> consumerFactory() {
Map<String, Object> props = new HashMap<>();
props.put(
ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG,
bootstrapAddress);
props.put(
ConsumerConfig.GROUP_ID_CONFIG,
groupId);
props.put(
ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG,
StringDeserializer.class);
props.put(
ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG,
StringDeserializer.class);
return new DefaultKafkaConsumerFactory<>(props);
}
@Bean
public ConcurrentKafkaListenerContainerFactory<String, String>
kafkaListenerContainerFactory() {
ConcurrentKafkaListenerContainerFactory<String, String> factory
= new ConcurrentKafkaListenerContainerFactory<>();
factory.setConsumerFactory(consumerFactory());
return factory;
}
I have created a consumer factory and a concurrentKafkaListenercontainer Factory. I have not set the concurrency for the listener Factory. I have a method annotated with @KafkaListener
@KafkaListener(topics = "topicName")
public void listen(String message) {
System.out.println("Received Message: " + message);
When I dont set the concurrency property, will Spring create 1 consumer instance, 1 kafka listener container belonging to a group specified in the consumer factory?
If i change the concurrency to 3, will spring create 3 consumer instances, so 3 consumers in the same consumer group specified while configuring consumer factory and 3 listener containers ?
Also, depending upon the concurrency and let's assume we are listening to only one topic now, we will have 3 methods annotated with @kafkalistener, all 3 if partition not specified listening to different partitions(provided by kafka in round-robin manner). ?
I am new to Kafka and wanted to clarify my understanding.