0
0
Spring Bootframework~20 mins

Kafka integration basics in Spring Boot - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Kafka Integration Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
What is the output when a Spring Boot Kafka listener receives a message?
Consider a Spring Boot Kafka listener configured to listen to topic "orders". When a message "Order123" is sent to this topic, what will the listener method print?
Spring Boot
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

@Component
public class OrderListener {

    @KafkaListener(topics = "orders")
    public void listen(String message) {
        System.out.println("Received: " + message);
    }
}
AReceived: Order123
BNo output, listener not triggered
CReceived: null
DOrder123
Attempts:
2 left
💡 Hint
The listener method prints a prefix before the message content.
📝 Syntax
intermediate
1:30remaining
Which Kafka producer configuration property sets the Kafka server address?
In Spring Boot Kafka producer configuration, which property key correctly sets the Kafka broker address to localhost:9092?
Aspring.kafka.producer.broker-address=localhost:9092
Bspring.kafka.bootstrap-servers=localhost:9092
Cspring.kafka.producer.server=localhost:9092
Dspring.kafka.producer.bootstrap-servers=localhost:9092
Attempts:
2 left
💡 Hint
The property includes 'producer' and 'bootstrap-servers'.
🔧 Debug
advanced
2:30remaining
Why does this Kafka listener fail to receive messages?
Given the following listener code, why does it not receive messages from the topic payments?
Spring Boot
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

@Component
public class PaymentListener {

    @KafkaListener(topic = "payments")
    public void listen(String message) {
        System.out.println("Payment received: " + message);
    }
}
AThe listener method must return a value.
BThe annotation property should be 'topics' not 'topic'.
CThe class must implement an interface to receive messages.
DThe method parameter type should be ConsumerRecord, not String.
Attempts:
2 left
💡 Hint
Check the spelling of the annotation property for topic subscription.
state_output
advanced
2:00remaining
What is the value of the message count after processing 3 messages?
A Spring Boot Kafka listener increments a counter each time it receives a message. After receiving 3 messages, what is the value of the counter?
Spring Boot
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

@Component
public class CountingListener {

    private int messageCount = 0;

    @KafkaListener(topics = "events")
    public void listen(String message) {
        messageCount++;
    }

    public int getMessageCount() {
        return messageCount;
    }
}
A0
B1
C3
DCannot determine without synchronization
Attempts:
2 left
💡 Hint
The counter increments once per message received.
🧠 Conceptual
expert
3:00remaining
Which option best describes the role of Kafka consumer groups in Spring Boot?
In Spring Boot Kafka integration, what is the main purpose of assigning consumers to the same consumer group?
ATo allow multiple consumers to share the load by dividing topic partitions among them
BTo ensure all consumers receive every message from the topic
CTo enable consumers to produce messages to the same topic
DTo prevent consumers from connecting to the Kafka broker simultaneously
Attempts:
2 left
💡 Hint
Think about how Kafka distributes messages to consumers in a group.