简体   繁体   English

REST与JAX-RS-异步调用

[英]REST with JAX-RS - Asynchronous call

I saw the below post from "cmd" which was posted couple of years back. 我看到几年前发布的“ cmd”下面的帖子。 And "Wojtek Owczarczyk" was answered this one. 而“ Wojtek Owczarczyk”得到了回答。 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. 1)一旦请求到达服务api,我将创建一个Job ID,并保留我的请求详细信息,并将ACCEPTED状态代码和Job ID一起发送回客户端。 2) Then, i will create the new thread for that request to continue with the requested operation. 2)然后,我将为该请求创建新线程以继续执行请求的操作。 3) After successful completion of Operation, I will send back the client with all status of the request. 3)操作成功完成后,我将把请求的所有状态发回给客户。 4) Finally, in callbackCompletion register i will remove the job id from my persistence list. 4)最后,在callbackCompletion寄存器中,我将从持久性列表中删除作业ID。

To implement the above logic, i need client to send his listener information along with request (basically URI). 为了实现上述逻辑,我需要客户端将其侦听器信息与请求(基本上是URI)一起发送。 This is to update the request status to client back, after processing the request. 这是在处理请求后将请求状态更新回客户端。

REST with JAX-RS - Handling long running operations REST with JAX-RS-处理长时间运行的操作

This is not how REST is meant to work in my opinion. 我认为这并不是REST的工作方式。 I would do the following approach instead: 我将改为采用以下方法:

  • Client makes a request for a long operation 客户要求长期操作
  • Create a job id and run the job asynchronously 创建一个作业ID并异步运行该作业
  • Return the accepted status together with the a URI to request the status for the job. 返回接受的状态以及URI,以请求作业的状态。 For example: http://.../resources/jobs/1234 例如: http://.../resources/jobs/1234

The client is now responsible eg to poll the URI to get the current status of the job execution. 客户端现在负责例如轮询URI以获取作业执行的当前状态。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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