简体   繁体   中英

REST with JAX-RS - Asynchronous call

I saw the below post from "cmd" which was posted couple of years back. And "Wojtek Owczarczyk" was answered this one. I am good with all the answer, except last line.

My Confusion is, If we return immediately with ACCEPTED status. Then, we will lost the track of the request.

So i am planning to implement below steps. Please correct me if i am wrong.

1) As soon as the request hits service api - I will create one Job Id and persist my request detail and send back the client with ACCEPTED status code along with Job id. 2) Then, i will create the new thread for that request to continue with the requested operation. 3) After successful completion of Operation, I will send back the client with all status of the request. 4) Finally, in callbackCompletion register i will remove the job id from my persistence list.

To implement the above logic, i need client to send his listener information along with request (basically URI). This is to update the request status to client back, after processing the request.

REST with JAX-RS - Handling long running operations

This is not how REST is meant to work in my opinion. I would do the following approach instead:

  • Client makes a request for a long operation
  • Create a job id and run the job asynchronously
  • Return the accepted status together with the a URI to request the status for the job. For example: http://.../resources/jobs/1234

The client is now responsible eg to poll the URI to get the current status of the job execution.

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