What is DefaultKafkaConsumerFactory?

Your thoughts?

|

Spring Kafka ultimately uses "real" Kafka to publish/consume from Kafka.

These consumers must be created with specific configuration like boot strap servers, consumer groups, topics, etc.

The ConsumerFactory is an interface for producing consumer instances, implemented by DefaultKafkaConsumerFactory.


|

DefaultKafkaConsumerFactory is the implementation for ConsumerFactory. This dictates how consumer instances will be created.

This is a typical Java based configuration for Spring Kafka...

@Configuration
public class KafkaConsumerConfig {
    @Bean
    public ConsumerFactory<String, String> consumerFactory() {
        Map<String, Object> props = new HashMap<>();
        props.put(
                ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG,
                "http://localhost:9092");
        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;
    }
}

Notice how the first bean returns a new DefaultKafkaConsumerFactory

Notice how the ConcurrentKafkaListenerContainerFactory sets it's consumer factory (for configuring it's instances)


|

A container factory creates container instances.

These container instances are ConcurrentMessageListenerContainer instances.

These are really collections of KafkaMessageListenerContainers

These KafkaMessageListenerContainers are consumers that can read from Kafka :)

DefaultKafkaConsumerFactory is THE implementation of the ContainerFactory interface.

|

The default factory for creating consumer instances.