Search code examples
javaspringapache-kafkaapache-kafka-streamsspring-kafka

How to measure the total time of an asynchronous process using Kafka topics?


I have the following microservices scenario

Microservice 1

1 - Collect a System.getCurrentTimeMillis

2 - Generate an id after an operation in the DB

3 - Send an object in json in the format below to the topic INICIO_PROCESSAMENTO

{
   "uuid": "b45ebe6f-d59a-4e37-9706-f546b32c68c3",
   "milliSeconds": 1600258507450
}

Microservice 7

1 - Finish processing the message with the ID generated in the first microservice

2 - Collect a System.getCurrentTimeMillis

3 - Send Json below for the topic FIM_PROCESSAMENTO

{
   "uuid": "b45ebe6f-d59a-4e37-9706-f546b32c68c3",
   "milliSeconds": 1600258508980
}

In this case, how can I measure the total time of the asynchronous transaction? One suggestion was to use Kafka Streams and maybe KTables, but I didn't understand how that would work.

An important point the message ID in Kafka is a long generated by Kafka / Driver. The ID of my operation exists only within the body of messages sent to topics.

The final objective is to be able to collect the total time of the process for analysis, initially we would use opentracing for this, but as we have an integration with third parties in the middle of the process and we depend on their return that comes without the transaction id we were unable to follow that way.


Solution

  • In this case I solved it using opentelemetry