Performance: Kafka integration basics
This affects the responsiveness and throughput of message processing in a web application, impacting how quickly data flows between services.
@KafkaListener(topics = "topicName")
public void consumeAsync(String message) {
CompletableFuture.runAsync(() -> processMessage(message));
}public void consume(String message) {
// process message synchronously
processMessage(message);
// blocks main thread
}| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Synchronous Kafka message processing | N/A | N/A | N/A | [X] Bad |
| Asynchronous Kafka message processing | N/A | N/A | N/A | [OK] Good |
@KafkaListener in a Spring Boot application?@KafkaListenerKafkaTemplate, not @KafkaListener.@KafkaListener listens to topics [OK]KafkaTemplate with the send() method to send messages.kafkaTemplate.send("topicName", "message") is the correct syntax to send a message.@KafkaListener(topics = "myTopic")
public void listen(String message) {
System.out.println("Received: " + message);
}myTopic?@Bean
public NewTopic topic() {
return new NewTopic("testTopic", 1, (short) 1);
}topicA and topicB. Which of the following @KafkaListener annotations correctly achieves this?topics = {"topicA", "topicB"}.Pass the test and this pattern moves unknown