mardi 24 septembre 2019

How to best implement transaction around business process in Java Spring Boot Application

I have looking for the best approach to handle error handling and retries for the following business feature.

begin business transaction

  1. User logs unto a website and triggers next step by clicking a button

  2. Book a venue : this calls a spring boot microservice which insert record to secure booking

  3. Send confirmation letter user

    • calls multiple springboot micro-services to fetch letter details and aggregates the data

    • generate letter by calling pdf generation microservice

    • sends letter by calling a external API

    • Log an event using a messaging queue

finish business transaction

The above flow is implemented in a restful endpoint The steps is called from a Java method, but steps 2 and 3a,b and c are delegates to sub methods.

My question is, what is the best approach to achieve a transaction like operation for this functionality, so that : - if booking venue (db insert) fails the letter is not sent out - if the notification fails, the database insert should be rolled back

I know about the @Transactional https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/transaction/annotation/Transactional.html

But, I will like a few ideas of pattern for this.

All the methods invoked have exception handling using @ControllerAdvice

Is there a Java @Transactional wrapper used to perform the following events - ( database operation, file reads, asynchronous call, messaging etc) as an atomic operation

Any ideas will be appreciated

Aucun commentaire:

Enregistrer un commentaire