您可以使用 Java 和 REST Web 服务进行异步通信吗?
您能否在使用有时需要几分钟才能返回值的 REST Web 服务的客户端上与 Java 进行异步通信?
在查看了以下内容后,我认为不是。然而,C# 确实允许此
用户1019776
执行异步 WCF 时首选哪种方式调用? 和 WCF 异步回调
但它们是否适用于 REST?可能不会。
关于客户端:如何使 WCF 客户端异步?
答:要处理异步 WCF 事件,您可以通过 Event 方法使客户端异步,请参阅:http://msdn.microsoft.com/en-us/library/wewwczdw.aspx
(但请确保它是异步“即发即忘”事件),另请参阅此线程在 Java 上(更多的是发布者/订阅者同步模型:Java 是否有本机支持事件,类似于C#的事件?)
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?
I think not, after reviewing the below. C# however does allow this
user1019776
Which way is preferred when doing asynchronous WCF calls? and
WCF asynchronous callback
but do they apply to REST? Probably not.
Re client: How do you make a WCF Client asynchronous?
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
(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#? )
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
有很多方法可以异步向 TCP 套接字发送数据,我不知道你指的是哪种类型。您能澄清一下您正在尝试做什么以及什么对您不起作用吗?什么样的服务需要几分钟?也许您应该担心修复服务。 – Peter Lawrey 8 小时前仅供参考,第一次通话时,REST 通信在握手时需要一段时间才能建立通信。通常比后续调用长 30 倍。这是众所周知的。谢谢。
您所提问题的答案很简单:“是的,当然。”您是否正在寻找如何在 Web 容器环境中执行此操作?帮助了解如何仅使用 JavaSE 编写解决方案?如何使用 Apache 异步 HttpClient? – Affe 8 小时前*Affe,是的,那会很有帮助。客户端是Android手机。感谢任何链接。 *
您可以通过不同的方式使用 Java IO、NIO 和 NIO2 来实现此目的。更不用说使用各种库来实现这一点的方法了。有很多库可以做到这一点,很难知道该推荐哪一个。 – Peter Lawrey 8 小时前 请推荐一个。谢谢。
好吧,Java 没有所谓的“事件”或“委托”之类的东西,但是它以各种方式支持异步通信。 – Peter Lawrey 8 小时前 怎么做?
FWIW,WCF 不需要使用 SOAP。您可以在其下使用其他RESTful协议。 @PeterLawrey 为您提供了 Java 所需的答案。 – ssamuel 7 小时前 我特别要求在我的 OP 中休息
** 我要感谢 stackoverflow 的志愿者。鉴于不支付任何费用,所提供的服务非常出色。谢谢,我稍后会检查此线程以获取后续回复。 **
There are some many ways to send data to a TCP socket asynchronously, I don't know what type you are referring to. 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. Often 30 times longer than subsequent calls. 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? Help with how to program a solution using only JavaSE? How to use Apache Async HttpClient? – Affe 8 hours ago *Affe, yes, that would be helpful. The client is an Android phone. Any links appreciated. *
You can do it with Java IO, NIO and NIO2 in different ways. 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. Thanks.
Ok, Java doesn't have a thing called an "event" or a "delegate" However it supports asynchronous communication in various ways. – Peter Lawrey 8 hours ago how?
FWIW, WCF doesn't need to use SOAP. You can use other RESTful protocols under it. @PeterLawrey gives you the answer you need for Java. – ssamuel 7 hours ago I specifically asked for REST in my OP
** I want to thank the volunteers here at 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. **