简体   繁体   English

服务器端Web服务异步的推荐模式

[英]Recommended patterns for server side web service asynchrony

I have successfully implemented both polling and callback client side asynchronous examples, but now I am interested in implementing a web service with server side asynchrony. 我已经成功实现了轮询和回调客户端异步示例,但是现在我对实现具有服务器端异步的Web服务感兴趣。 The infrastructure is Java EE using JBoss AS 6.x. 该基础架构是使用JBoss AS 6.x的Java EE。

The pattern (as I understand it) that I am trying to implement would involve two web service operations, one to initiate a request and a second to check to see if a request is done and retrieve the results. 我正在尝试实现的模式(据我所知)将涉及两个Web服务操作,一个用于启动请求,第二个用于检查是否已完成请求并检索结果。

  1. Client invokes web service endpoint operation 1 with search parameters via SOAP over HTTP. 客户端通过HTTP上的SOAP使用搜索参数调用Web服务端点操作1。
  2. Web service endpoint sends the request over JMS queue 1 to a message driven bean. Web服务端点通过JMS队列1将请求发送到消息驱动的Bean。
  3. Message driven bean (MDB) picks up the request from queue 1. 消息驱动bean(MDB)从队列1接收请求。
  4. MDB acknowledges service request by sending a message containing a correlator ID over JMS queue 2 to the web service endpoint. MDB通过在JMS队列2上向Web服务端点发送包含相关器ID的消息来确认服务请求。 (I am assuming this correlator ID will be the JMS message id generated.) (我假设此相关器ID将是生成的JMS消息ID。)
  5. MDB acknowledges the original message to remove it from queue 1. MDB确认原始消息已将其从队列1中删除。
  6. MDB begins long running database query, presumably building results to a temp table using the correlator ID as the retrieval key. MDB开始长期运行的数据库查询,大概是使用相关器ID作为检索关键字将结果构建到临时表中。
  7. Web service endpoint sends back reply containing correlator ID to the Client via SOAP over HTTP. Web服务端点通过HTTP上的SOAP将包含相关器ID的回复发送回客户端。

I am guessing that, since picking up the results doesn't involve a long query, I don't need JMS, I can simply query the database to see if results are ready. 我猜想,由于获取结果并不涉及冗长的查询,因此我不需要JMS,因此我可以简单地查询数据库以查看结果是否准备就绪。 So, the second operation would be: 因此,第二个操作将是:

  1. Client invokes web service endpoint operation 2 with correlator ID via SOAP over HTTP. 客户端通过HTTP上的SOAP使用相关器ID调用Web服务端点操作2。
  2. Web service queries database using correlator ID. Web服务使用相关器ID查询数据库。 Result code would be: no results found, operation still in progress, or results found. 结果代码为:未找到结果,仍在进行操作或找到结果。
  3. Web service responds to Client with some sort of complex structure that would combine the result code along with any results. Web服务以某种复杂的结构响应客户端,该结构会将结果代码与任何结果结合在一起。

So, I have many questions. 所以,我有很多问题。 I have seen some references to server side support for asynchrony, but they all seem to be server specific in some way. 我已经看到一些服务器端对异步支持的参考,但是它们似乎都以某种方式特定于服务器。 For example, I have seen a diagram describing this first operation exactly, but it seems to be OC4J specific. 例如,我看到了一个准确描述此第一个操作的图,但它似乎是OC4J特有的。 If anyone can direct me to an generic example or tutorial implementing something like this, please do. 如果有人可以指导我学习实现此类示例的通用示例或教程,请这样做。 Other subleties might be, should I use the JMS message ID as the correlator to return to the client? 其他子类可能是,我是否应该使用JMS消息ID作为相关器以返回到客户端? I am assuming I should use CLIENT-ACKNOWLEDGE as the JMS session mode so that the MDB can send a reply to the web service and then remove the message from the queue. 我假设我应该将CLIENT-ACKNOWLEDGE用作JMS会话模式,以便MDB可以向Web服务发送答复,然后从队列中删除消息。 Or, should I even bother? 还是我应该打扰? Should the web service endpoint just generate a JMS message, pop it in the queue and return the message ID directly to the service client without going through all the rigamarole of having the MDB send back a correlator via JMS queue 2? Web服务端点是否应该仅生成JMS消息,将其弹出到队列中,然后将消息ID直接返回给服务客户端,而不必经历使MDB通过JMS队列2发回相关器的所有麻烦呢? [edit: Actually, the more I consider it, it seems wrong that the web service would send a message and then, what, block on waiting for a reply on queue 2? [编辑:实际上,我考虑得更多,Web服务将发送一条消息然后在等待队列2上的等待时阻止,这似乎是错误的? ] ]

Correlation id can be generated at step 2 and immediately returned to the client. 可以在步骤2生成关联ID,并立即将其返回给客户端。 That reduces additional hops before responding to the client. 这样可以减少响应客户端之前的额外跃点。 Generating a persistent message into the queue should suffice. 将持久性消息生成到队列中就足够了。 I also dont see the need for two queues. 我也看不到需要两个队列。 I prefer an application generated correlation id. 我更喜欢应用程序生成的关联ID。

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

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