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?
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?
Yes we can easily configure in spring-boot java application:
Add below dependency:
<dependency>
<groupId>org.springframework.kafka</groupId>
<artifactId>spring-kafka</artifactId>
</dependency>
Add Below Properties:
spring.kafka.consumer.bootstrap-servers=localhost:9092
spring.kafka.consumer.key-deserializer=org.apache.kafka.common.serialization.StringDeserializer
spring.kafka.consumer.value-deserializer=org.apache.kafka.common.serialization.StringDeserializer
spring.kafka.consumer.properties.message.max.bytes=100000000
spring.kafka.consumer.properties.max.request.size=100000000
spring.kafka.consumer.group-id=eventmanager
spring.kafka.consumer.properties.spring.json.trusted.packages=*
Next Add below Java Code:
@Component
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);
handleEvent(eventRequest);
} 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.
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