Spring Boot Kafka Interview Questions

1) What's an easy way to create a new topic with Spring Boot?

You can create a new topic via Spring Boot configuration by defining a NewTopic @Bean in the application context:

public NewTopic topic1(){
    return TopicBuilder.name("myTopic")

2) Is a KafkaAdmin bean automatically registered for you when using Spring Boot?


3) What happens when a broker is not available when starting the Spring Boot app?

The default behavior is the Spring context continues to load. You can optionally consider this behavior fatal by configuring the fatalIfBrokerNotAvailable property on the admin.

4) How is the KafkaTemplate class used in Spring Boot?

The KafkaTemplate class wraps a Kafka producer and makes it easy to send data to a topic using Spring Boot...

5) What is a Message Listener?

The message listener is an interface for handling incoming messages. There are 8 supported interfaces for message listeners. The MessageListener is called for each record returned by the underlying consumer poll() method.

6) What's the difference between KafkaMessageListenerContainer and ConcurrentMessageListenerContainer?

A KafkaMessageListenerContainer receives messages for all topics and partitions on a single thread. A ConcurrentMessageListenerContainer is a collection of KafkaMessageListenerContainer instances. It distributes message consumption across multiple threads.

7) What is the @KafkaListener annotation?

The @KafkaListener annotation can be applied to Java classes, methods, and method annotations. @KafkaListener is most commonly applied to methods, registering Kafka listener containers for those methods...

@KafkaListener(topics = "test")
public void processMessage(String content){
    System.out.println("Message received: " + content);

In the above example, the processMessage() method is annotated with @KafkaListener. This method will be invoked when messages are read from the test topic.

Your thoughts?