Java Async REST web service using Jersey?(使用 Jersey 的 Java Async REST Web 服务?)
问题描述
我需要实现一个 Java REST Web 服务(我们使用 Jersey 框架),基本上可以
I need to implement a Java REST Web Service (we use Jersey framework) which can basically either
一个.在返回响应之前阻塞等待某个事件(或轮询事件)湾.提供某种 aysnc 行为以在请求已处理时通知客户端.
a. block waiting for some event (or poll for the event), before returning the response b. provide some kind of aysnc behaviour to notify the client when the request has been processed.
我正在考虑返回一个 transationID,并有一个/status 端点,客户端应该轮询该端点以确定请求是否已处理并获得特定结果.
I was thinking of returning a transationID, and having a /status endpoint which the client should poll to determine if the request was processed and get a specific result.
有什么想法吗?
推荐答案
Alan,正确的做法是使用 HTTP 的 202 Accepted 返回码,并在响应正文中包含一个链接,该链接指向客户端可以轮询以检查请求状态的页面.
Alan, the right thing to do is to use HTTP's 202 Accepted return code and include in the response body a link that points to a page the client can poll to check the status of the request.
在 machine2machine 上下文中,您需要为这些响应设计媒体类型(或微格式等),以便机器客户端可以理解"它们.
In a machine2machine context you will need to design your media type (or microformat etc.) for those responses so a machine client can 'understand' them.
参见 http://www.w3.org/协议/rfc2616/rfc2616-sec10.html#sec10.2.3
也许还为此目的查看几乎标准化的新 HTTP Link 标头.
Maybe also look at the almost standardized new HTTP Link header for that purpose.
https://datatracker.ietf.org/doc/html/draft-nottingham-http-link-header-03
一月
这篇关于使用 Jersey 的 Java Async REST Web 服务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:使用 Jersey 的 Java Async REST Web 服务?
基础教程推荐
- REST Web 服务返回 415 - 不支持的媒体类型 2022-01-01
- 问题http://apache.org/xml/features/xinclude测试日志4j 2 2022-01-01
- 修改 void 函数的输入参数,然后读取 2022-01-01
- 存储 20 位数字的数据类型 2022-01-01
- 无法复制:“比较方法违反了它的一般约定!" 2022-01-01
- 如何对 Java Hashmap 中的值求和 2022-01-01
- RabbitMQ:消息保持“未确认"; 2022-01-01
- Struts2 URL 无法访问 2022-01-01
- Spring AOP错误无法懒惰地为此建议构建thisJoinPoin 2022-09-13
- 使用堆栈算法进行括号/括号匹配 2022-01-01
