0

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

Community
  • 1
  • 1
Mohan
  • 699
  • 1
  • 11
  • 27
  • 'After successful completion of Operation, I will send back the client with all status of the request.'... you can't do that because you already responded to that request when set ACCEPTED. Unless you keep pinging the server requesting for the status operation – fmodos Jan 28 '16 at 20:29
  • Thanks for your response fmodos. – Mohan Jan 28 '16 at 21:07

1 Answers1

0

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 e.g. to poll the URI to get the current status of the job execution.

simdevmon
  • 673
  • 7
  • 14
  • Thanks for your response simdevmon. Actually, i can go for pollable method. I got a requirement not to use pollable, but to use callback. But as per my understanding that callable holds good only in case of job takes <30 sec. So only i was doing this approach. But this need some kind of service running in client side also. So by using request url (which is url for client service) i will make a call to client with all status for the request from my service. – Mohan Jan 28 '16 at 21:08
  • Yes, with REST I would really go for polling. The design of REST is really different in comparison with CORBA for example, which supports callback objects natively. If you misuse REST in that way, you might face several issues like network restrictions (if the clients have to run a service), messed up service hierarchy and so forth... – simdevmon Jan 29 '16 at 10:23
  • Thanks simdevmon. I totally agree with you and i will try to convince my boss. – Mohan Jan 29 '16 at 14:37