I am doing a POC with Spring Boot & Kafka for a transactional project and I have the following doubt:
Scenario: One microservices MSPUB1 receives Requests from the customer. That requests publish a message on topic TRANSACTION_TOPIC1 on Kafka but that Microservice could receive multiple requests in parallel. The Microservice listens the topic TRANSACTION_RESULT1 to check that the transaction finished.
In the other side of the Streaming Platform, another Microservice MSSUB1 is listening the topic TRANSACTION_TOPIC1 and process all messages and publish the results on: TRANSACTION_RESULT1
What is the best way from MSPUB1 to know if the message on topic TRANSACTION_RESULT1 matches with his original request? The microservice MSPUB1 could have a ID for any message published on the initial topic TRANSACTION_TOPIC1 and be moved to TRANSACTION_RESULT1
Question: When you are reading the partition, you move the pointer but in a concurrency environment with multiple requests, how to check if the message on the topic TRANSACTION_RESULT1 is the expected?
Many thanks in advance
Juan Antonio
One way to do it is to use a Spring Integration
BarrierMessageHandler
.Here is an example app. Hopefully, it's self-explanatory. Kafka 0.11 or higher is needed...
Result
Pom
application.properties
EDIT
And here is a version that uses Spring Integration on the server side, instead of
@KafkaListener
...and