简体   繁体   English

您可以与Java和REST Web服务进行异步通信吗?

[英]Can you do asynchronous communications with Java and REST web services?

Can you do asynchronous communications with Java on a client that is consuming a REST web service that sometimes takes several minutes to return a value? 您是否可以在使用REST Web服务的客户端上与Java进行异步通信,该客户端有时需要几分钟才能返回值?

I think not, after reviewing the below. 在查看以下内容后,我认为不是。 C# however does allow this C#确实允许这样做

user1019776 用户名

Which way is preferred when doing asynchronous WCF calls? 进行异步WCF调用时,首选哪种方式? and WCF asynchronous callback WCF异步回调

but do they apply to REST? 但是它们适用于REST吗? Probably not. 可能不是。

Re client: How do you make a WCF Client asynchronous? 关于客户端: 如何使WCF客户端异步?

Answer: to handle asychronous WCF events,you make the client asynchronous via an Event method, see: http://msdn.microsoft.com/en-us/library/wewwczdw.aspx 答:要处理异步WCF事件,可以通过Event方法使客户端异步,请参阅: http : //msdn.microsoft.com/zh-cn/library/wewwczdw.aspx

(but make sure it is an Asychronous “fire and forget” event), see also this thread on Java (more of a Publisher/subscriber synchronous model: Does Java have native support for events, similar to that of C#? ) (但请确保它是一个异步的“触发并忘记”事件),另请参见Java上的该线程(更多的发布者/订阅者同步模型: Java是否对事件具有本机支持,类似于C#?

There are some many ways to send data to a TCP socket asynchronously, I don't know what type you are referring to. 有很多方法可以将数据异步发送到TCP套接字,但我不知道您指的是哪种类型。 Can you clarify what you are trying to do and what doesn't work for you? 您能说明您要做什么,什么不适合您吗? What sort of service takes several minutes? 哪种服务需要几分钟? Perhaps you should worry about fixing the service. 也许您应该担心修复服务。 – Peter Lawrey 8 hours ago FYI REST communications take a while on the handshake on the first call to establish a communication. – Peter Lawrey 8小时前,第一次建立通信时,FYI REST通信在握手时需要花费一些时间。 Often 30 times longer than subsequent calls. 通常比后续通话时间长30倍。 This is well known. 这是众所周知的。 Thanks. 谢谢。

The answer to the question you asked is simply "yes, of course." 您提出的问题的答案只是“当然可以”。 Are you looking for how to do it inside a web container environment? 您是否正在寻找如何在Web容器环境中进行操作? Help with how to program a solution using only JavaSE? 帮助如何仅使用JavaSE编程解决方案? How to use Apache Async HttpClient? 如何使用Apache Async HttpClient? – Affe 8 hours ago * Affe, yes, that would be helpful. – 8小时前Affe * Affe,是的,这将有所帮助。 The client is an Android phone. 客户端是Android手机。 Any links appreciated. 任何链接表示赞赏。 * *

You can do it with Java IO, NIO and NIO2 in different ways. 您可以通过不同的方式对Java IO,NIO和NIO2进行操作。 Not to mention ways of doing it with various libraries. 更不用说使用各种库的方式了。 There are so many libraries to do this, it is hard to know which one to recommend. 有太多的库可以做到这一点,很难知道推荐哪一个。 – Peter Lawrey 8 hours ago Please recommend one. -彼得Lawrey 11小时前请推荐一个。 Thanks. 谢谢。

Ok, Java doesn't have a thing called an "event" or a "delegate" However it supports asynchronous communication in various ways. 好的,Java没有所谓的“事件”或“代理”,但是它以各种方式支持异步通信。 – Peter Lawrey 8 hours ago how? – Peter Lawrey 8小时前如何?

FWIW, WCF doesn't need to use SOAP. FWIW,WCF不需要使用SOAP。 You can use other RESTful protocols under it. 您可以在其下使用其他RESTful协议。 @PeterLawrey gives you the answer you need for Java. @PeterLawrey为您提供Java所需的答案。 – ssamuel 7 hours ago I specifically asked for REST in my OP – ssamuel 7小时前, 我在OP中特别要求REST

** I want to thank the volunteers here at stackoverflow. ** 我要感谢stackoverflow的志愿者。 Given that no money is being paid the service provided is outstanding. 由于没有钱被支付,所提供的服务是优秀的。 Thanks and I'll check this thread later for any subsequent replies. 谢谢,稍后我将检查此线程以获取任何后续回复。 ** **

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

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