Spring boot unique id for every transaction - spring

I have the following use case -
The user fills up a form.
The spring boot backend code calls multiples services before pushing the user data to the database.
The database takes more than 10 secs to commit the details
Since the whole process takes time, I want to return a transaction id to the user immediately after he fills up the form. The user can check the status later using the same transaction Id.
Does spring boot provide any feature to achieve this?

Related

How to send rest request for only particular records in a Oracle database table using Spring Boot

I have created a simple service using Spring Boot. There is a table Message_Queue as shown in this image link -
Message_Queue Table
I am using oracle database. Here, msisdn is a number which is primary key, and it has some other fields like sim_number, activation_date, subscription_id.
There is another Spring Boot service which sends rest API request to add the activation_date and subscription_id details for the respective record in message_queue table. Table message_queue holds data upto 2 million records.
I want to create a scheduled task in my Spring Boot application, which will send rest API request to some other 3rd service only for those records which has activation_date and subscription_id details filled and will also delete that record from the table.
What is the best way to achieve that using Spring Boot framework? Please try to answer on the enterprise level standards.
Is it a good approach to fetch like 1000 records with pagination until all the records are not checked from the table and then check for each record if it has activation_date and subscription_id or not, if it has then send a rest request for the record and also a delete request to the DB for the same record?

Calling saveAndFlush within a JPA Transaction

I have an application that persists data within a transaction using JPA 'save'. A second application accesses this data asynchronously on receiving a message from the first application. However, depending on timing the data is sometimes not accessible by the second application as the main transaction has not yet completed (or is delayed). I am considering changing 'save' to 'saveAndFlush'. Will this ensure that the objects are saved contemporaneously? Will the objects persisted with 'saveAndFlush' be rolled back on a transaction failure?
Objects persisted with saveAndFlush will be rolled back but this will not solve your real problem as changes wont be visible to a request from the second application until the transaction is committed.

Cache refresh on spring boot whenever Data update happens in Database from third party application also(Update will not happening by our application )

I need to refresh my Cache as soon as DB changes happened ,update might happen to DB from another source also not from my application in MySql. How can I do that as mysql will not provide access to call java method as part of TRigger as like in Oracle? (SpringBoot application)

Spring Boot: how to implement workflow as synchronous REST services integrating external applications

I'm here to ask you for a suggestion on which technology to use to add new features on an existing application based on Spring Boot.
The new features consist of some workflows, exposed as synchronous REST services, that must update the database and call REST services exposed by external applications, which consequently will update their own database.
For example, a service could implement this workflow:
insert rows in database
call the REST service of the application X, which will update its database
update rows in database
call the REST service of the application Y, which will update its database
update rows in database
This workflow must be synchronous and it is started from an human operator that will receive the outcome in few seconds.
If, for example, the step 4) fails, I need to:
make a compensation, calling another REST service of the application X, in order to undo what it made in step 2)
rollback the insert/update made in my database in steps 1) and 3)
Which technology, framework, tool or other would you use? In the past I implemented a similar scenario using Oracle SOA, but in this case I would avoid to introduce a new infrastructure in my application based on Spring Boot.
Thank you
I guess you need to learn a bit more about Spring Framework and Spring Boot.
1.insert rows in database : Spring Data JPA
2.call the REST service of the application X, which will update its database : A Http Client such as RestTemplate or WebClient
3.update rows in database : Spring Data JPA (again)
4.call the REST service of the application Y, which will update its database update rows in database : RestTemplate...
So so and so...
If you want to make a real workflow, you can use Activiti.

How to Restart Spring boot application (or just a particular instance of a class) when flyway migrate is ran or a new schema version is added

I have a particular instance of a class that loads some data from the database, so every time the database is updated the system should recreate the instance of that class to get the updated data
There are trivial several solutions:
(1) Use scheduling to load the latest data from DB periodically.
(2) Provide a web service such as RESTful API to load the latest data from DB.
(3) If your DB supports event-driven listeners, you can trigger your application to achieve this either by invoking a service described in (2) or send a message to queue and handle it by consumer.

Resources