How to subscribe to Kafka (to listen to events) in Java

I want to subscribe to the events emitted by Vahana in my custom code. What is the best way of doing this?

Is there any code samples available for it?

@Vikas_Dhillon @shivang.garg @Mayank @naveen.gupta

Yes we can easily configure in spring-boot java application:

Add below dependency:


Add Below Properties:


Next Add below Java Code:

public class EventConsumer {
    private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();

    @KafkaListener(topics = "<YOUR_KAFKA_TOPIC>")
    public void consumeEvent(String message) {
        log.trace("Message from Kafka Topic : {} ", message);
        try {
            EventRequest eventRequest = OBJECT_MAPPER.readValue(message, EventRequest.class);
        } catch (JacksonException jpe) {
            log.error("Unable to parse kafka message json to EventRequest {} ", jpe.getMessage());
        } catch (Exception ex) {
            log.error("Exception in reading message from Kafka Topic message {} ", ex.getMessage(), ex);

And where to find this Kafka topic from Vahana portal?

Current we are not exposing any Kafka Topic on Vahana Portal.

But there are multiple Topics using in Vahana Ecosystem, You must know in which topic you are write your event.

I think we can ask this from Infra/DevOps team.

1 Like

In vahana we use kafka in the pipeline of logs
the topic name as per my knowledge is → LOGS
further you can confirm with infra/devops team