简体   繁体   English

Java EE中的双工流

[英]Duplex streaming in Java EE

I'm looking for a full duplex streaming solution with Java EE. 我正在寻找使用Java EE的全双工流解决方案。

The situation: client applications (JavaFX) read data from a peripheral device. 情况:客户端应用程序(JavaFX)从外围设备读取数据。 This data needs to be transferred in near real-time to a server for processing and also get the response back asynchronously, all while it keeps sending new data for processing. 这些数据需要近乎实时地传输到服务器进行处理,并且异步地获得响应,同时它不断发送新数据进行处理。

Communication with the server needs to have an overhead as low as possible. 与服务器的通信需要尽可能低的开销。 Data coming in is basically some sensor data and after processing it is turned in what can be described as a set of commands. 进入的数据基本上是一些传感器数据,并且在处理之后它被转入可以被描述为一组命令。

What I've looked into: 我调查了什么:

  1. A TCP/IP server (this is a non-Java EE approach).This would be the obvious solution. TCP / IP服务器(这是一种非Java EE方法)。这将是一个显而易见的解决方案。 Two connections opened in parallel from each client app: one for upstream data and one for downstream data. 每个客户端应用程序并行打开两个连接:一个用于上游数据,另一个用于下游数据。
  2. Remote & stateless EJBs. 远程和无状态EJB。 This would mean that there's no streaming involved and that I pack sensor data in smaller windows (1-2 seconds worth of sensor data) which I then send to the server for processing and get the processing result as a response. 这意味着没有涉及流媒体,我将传感器数据打包在较小的窗口(1-2秒的传感器数据)中,然后我将其发送到服务器进行处理并获得处理结果作为响应。 For this approach, while it is scalable, I am not sure how fast it will be considering I have to make a request each 1-2 seconds. 对于这种方法,虽然它是可扩展的,但我不确定考虑到每1-2秒发出请求的速度有多快。 I still need to test this but I have my doubts. 我仍然需要测试这个,但我有疑虑。
  3. RMI. RMI。 Is this any different than EJBs, technically? 这在技术上是否与EJB有所不同?
  4. Two servlets (up/down) with long polling. 两个带有长轮询的servlet(向上/向下)。 I've not done this before, so it's something to be tested. 我之前没有这样做过,所以要测试一下。

For now I would like to test the performance for my approach #2. 现在我想测试我的方法#2的性能。 The first solution will work for sure, but I'm not too fond of having a separate server (next to Tomcat, where I already have something running). 第一个解决方案肯定会起作用,但我不太喜欢拥有一个单独的服务器(在Tomcat旁边,我已经运行了一些东西)。

However, meanwhile, it would be worth knowing if there are any other Java specific (EE or not) technologies that could easily solve this. 然而,同时,值得知道是否有任何其他Java特定(EE或非)技术可以轻松解决这个问题。 If anyone has an idea, then please share it. 如果有人有想法,请分享。

This looks like a good place for using JMS . 这看起来像是使用JMS的好地方。 Instead of stateless EJBs, you will probably be using Message-Driven Beans . 您可能会使用Message-Driven Beans而不是无状态EJB。

This gives you an approach similar to your first solution, using two message queues instead of TCP/IP connections. 这为您提供了类似于第一个解决方案的方法,使用两个消息队列而不是TCP / IP连接。 JMS makes your communications fully asynchronous and is low-overhead in the sense that your clients can send messages as fast as they can regardless of how fast your server can consume them. JMS使您的通信完全异步,并且在您的客户端可以尽可能快地发送消息的意义上是低开销,而不管服务器使用它们的速度有多快。 You also get delivery guarantees and other JMS goodness. 您还可以获得交付保证和其他JMS善良。

Tomcat does not come with JMS, however. 但是,Tomcat没有附带JMS。 You might try TomEE or integrate your existing Tomcat with a JMS implementation like ActiveMQ . 您可以尝试使用TomEE或将现有的Tomcat与ActiveMQ等JMS实现集成。

There are numerous options you could try. 你可以尝试很多选择。 Appropriate solutions depend on the nature of your application, communication protocol, data transfer type, control you have over the client and server and firewall restrictions on client server routes. 适当的解决方案取决于应用程序的性质,通信协议,数据传输类型,对客户端和服务器的控制以及客户端服务器路由上的防火墙限制。

There's not much info on this in your question, but given what you have provided, you may like to look at netty as it is quite general purpose and flexible and seems to fit your requirements. 在您的问题中没有太多关于此的信息,但鉴于您提供的内容,您可能希望看看netty,因为它非常通用且灵活,似乎符合您的要求。 Netty also includes a duplex websocket implementation. Netty还包括双工websocket实现。 Note that a netty based solution may be more complex to implement and require more background study than some other solutions (such as jms). 请注意,基于netty的解决方案实现起来可能更复杂,并且需要比其他一些解决方案(例如jms)更多的背景研究。

Yet another possible solution in GraniteDS , which advertises a JavaFX client integration and multiple server integrations for full duplex client/server communication, though I have not used it. GraniteDS中的另一个可能的解决方案,它宣传JavaFX客户端集成和多服务器集成以进行全双工客户端/服务器通信,尽管我还没有使用它。 GraniteDS uses comet (your two asynchronous servlets with long polling model) with the Active Message Format for data which you may be familiar with from Flex/Flash. GraniteDS使用Comet(您的两个具有长轮询模型的异步servlet)和您可能熟悉的Flex / Flash数据的Active Message Format。

Have you looked at websockets as a solution? 你看过websockets作为解决方案吗? They are known to keep persistent connections and hence the asynchronous response will be quick. 众所周知,它们会保持持久连接,因此异步响应会很快。

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

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