本文介绍了异步Web服务流的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一些框架,将帮助我通过HTTP进行异步数据流。它可能看起来像SOAP WS或somethign别人。我不知道如果我没有名字,所以这里正是我需要的:

I need some framework that will help me to do asynchronous streaming over http. It may look like SOAP WS or somethign else. I don't know if I name it correctly, so here is what I need:

服务器A想使通过HTTP远程服务器B的请求。请求包含任意信息。结果为它是将包含相同类型的多个记录。其中有些是立即可用,其他可用版本。服务器A希望尽快获得可用的结果,而无需等待,直到所有的结果都可用。在现实世界服务器B将在不同数据源中搜索,其中一些是更敏感的其它

ServerA wants to make a request to remote ServerB over http. The request contains arbitrary information. Result for it is going to contain multiple records of the same type. Some of them are available immediately, other are available later. ServerA wants to get available results as soon as possible, without waiting until all results are available. In real world ServerB will search across different data sources, some of which are more responsive that other.

我能想到的3种解决方案。首先,服务器A产生的要求随机ID,执行SOAP请求

I can think of 3 kinds of solution. First, ServerA generates random id of request, performs SOAP request

void ServerB.startSearch(id, request);

这将立即返回,然后周期性调用

that will return immediately, and then A periodically calls

Result[] ServerB.areThereAnyNewResults(id);

所以,服务器A民调SERVERB脱颖而出的新reasults。我把这种方法投票。它涉及到B从A建立多个连接,另一种方案是在ServerA侧暴露接收服务,如

So ServerA polls ServerB fore new reasults. I call this method polling. It involves multiple connections established from A to B. Another solution is to expose receiving service on ServerA side, like

ServerA.acceptResults(String id, Result[] newResults);

和电话

ServerB.startSearch(id, request, serverAReceivingServiceEndpoindAddress);

所以,服务器B推新成果ServerA.acceptResults(),当新的结果是可用的。我把它推。它涉及到从B到A建立的B和多个连接从建立一个连接。

So ServerB pushes new results to ServerA.acceptResults() when new results are available. I call it pushing. It involves 1 connection established from A to B and multiple connection established from B to A.

另一个选择是在流相同的HTTP通道的结果,单一的响应中。

Another option is to stream results over same http channel, within single response.

A执行HTTP调用(我不知道,如果它可以是SOAP或者应该是别的东西),B开始搜索,当新的结果可用,它发送他们通过HTTP流并刷新它,所以他们可能会提供在A面立即生效。它不会关闭HTTP连接,直到所有的结果都可用。它涉及到从A到B只有单一连接,这就是为什么我会preFER使用它。我把它叫做流。我明白,如果某些代理上缓存响应内容的方式,它可能无法正常工作。

A performs http call (I don't know if it can be SOAP or should be something else), B starts searching and when new results are available, it sends them over http stream and flushes it, so they may be available on the A side immediately. It does not close http connection until all results are available. It involves only single connection from A to B, thats why I would prefer to use it. I call it streaming. I understand that it may not work if some proxy is on the way that buffers the response content.

所以,我的问题是,如果有任何解决方案,将完成大部分的工作对我来说。我想要做的就是调用这样code对A面

So, my question is if there is any solution that will do most of the work for me. What I'd like to do is call such code on A side

Service s = new RemoteAsyncService("http://serverb.com/serviceEndpoint", RemoteAsyncService.STREAMING);
// or RemoteAsyncService.POLLING, or RemoteAsyncService.PUSHING
Request r = new Request(...);
Callback callback = new Callback(){
 void newResults(Result[] result){...}
 // e should be null if finished correctly
 void requestFinished(RemoteException e){...}
}
s.search(request, callback);

和实现它ServerB上侧

And implement it on ServerB side

public ServiceImpl implements Service{
  void search(Request r, Callback c){
   // perform search, call c.newResult() when new results are available
  }
}

和其余由框架处理,包括重新建立连接时,它被丢弃,下降到投票站/推流,如果不能,因为缓冲代理来完成,调用callback.requestFinished()时,服务器B完成的工作或抛出异常,等Probbaly也应该以某种标准方式处理身份验证。

And the rest is handled by framework, including reestablishing connection when it is dropped, falling to polling/pushing if streaming can not be done because of buffering proxy, calling callback.requestFinished() when ServerB finishes work or throws the exception, etc. Probbaly it should also handle authentication in some standard way.

那么,有没有它抽象commuinication做的方法的任何解决方案,并且是capabale尽可能流的?

So, is there any solution that abstracts the way commuinication is done, and is capabale of streaming when possible?

如果没有的话,你认为这将是实现它作为开源有用吗? :)

If there is not, do you think it would be useful to implement it as open source? :)

推荐答案

你在说什么像一颗彗星的服务声音。你可以在这里阅读维基百科条目:

What you're talking about sounds like a COMET service. You can read the Wikipedia entry here:

不知道你会如何在Java中实现类似的东西,但在.NET中你可以使用WCF服务双工合同。你可以阅读更多有关如何获取和交流与服务的这种风格在这里:

Not sure how you'd implement something like that in Java, but in .NET you can use a Duplex contract for a WCF service. You can read more about how to access and communicate with that style of service here:

这篇关于异步Web服务流的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 05:28