Created
February 1, 2022 13:29
-
-
Save mmafrar/0f1d9013369875ec0bba34286a2ffe1c to your computer and use it in GitHub Desktop.
Getting Started with Apache Kafka and Spring Boot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.kafka; | |
import org.slf4j.Logger; | |
import org.slf4j.LoggerFactory; | |
import org.springframework.kafka.annotation.KafkaListener; | |
import org.springframework.kafka.support.KafkaHeaders; | |
import org.springframework.messaging.handler.annotation.Header; | |
import org.springframework.stereotype.Service; | |
@Service | |
public class Consumer { | |
private final Logger logger = LoggerFactory.getLogger(Consumer.class); | |
@KafkaListener(id = "myConsumer", topics = "purchases", groupId = "spring-boot", autoStartup = "false") | |
public void listen(String value, | |
@Header(KafkaHeaders.RECEIVED_TOPIC) String topic, | |
@Header(KafkaHeaders.RECEIVED_MESSAGE_KEY) String key) { | |
logger.info(String.format("Consumed event from topic %s: key = %-10s value = %s", topic, key, value)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment