简体   繁体   中英

Spring Boot - Stopping the Incoming request when Another API is in progress

The application is using Spring boot 2.7.0. I have an API - "/stopRunningJobs" and when this is triggered all the running spring batch jobs/APIs are stopped. Now, while this API is stopping all the running jobs, there may be a possibility of another API being called, which may end up in the "in-progress" or "completed" state rather than the "STOPPED" state. So, two inputs are needed-

  1. Is there a way in a spring boot, we can stop all other incoming requests to this container or application when "/stopRunningJobs" API is running ?
  2. Or, can we queue up all the incoming requests until "/stopRunningJobs" API processing is over and it resumes post that.

Any input is appreciated. Thank you

After doing some research - I could not find any inbuilt annotation on this. We will have to manually queue all the incoming requests and persist the request at the database layer with all the needed parameters. When the API - "/stopRunningJobs" is completed, we can write a method or an API to fetch all the queued request from the database, iterate it along with the param and invoke the API asynchronously.

Thank you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM