是否有“套接字连接池”? Java EE 应用程序有哪些类型?
我正在编写 JAX-RS Web 服务。它通过以下方式响应客户端调用:
- 从数据库检索一些信息
- 调用外部服务器
对于 2),服务器不公开 Web 服务接口(即没有 WSDL 接口或 REST API)。相反,它使用基于 TCPIP 的自定义协议。我希望从我的 JAX-RS 资源直接向此服务器发出客户端调用,但我不想每次调用 JAX 时都必须打开连接、进行身份验证并关闭连接-RS资源。有办法解决这个问题吗?换句话说,是否有类似“套接字连接池”之类的东西可供 Java EE 应用程序使用?我必须使用 ESB 之类的东西吗?还是有我忽略的替代方案?
I'm writing a JAX-RS web service. It responds to client invocations by:
- Retrieving some info from a database
- Making a call to an external server
For 2) the server does not expose a web service interface (i.e. no WSDL interface or REST API). Instead, it uses a custom protocol over TCPIP. I'd like to make client calls from my JAX-RS resource directly to this server but I don't want to have to open a connection, authenticate, and close the connection for each call to my JAX-RS resource. Is there a way around this? In other words, is there something like a "socket connection pool" available to Java EE apps? Would I have to use something like an ESB? Or is there an alternative that I'm overlooking?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
执行此操作的“正确”方法是为外部服务器编写JCA 连接器。 JCA 是 Java EE 堆栈的一部分,其确切目的是:提供从应用程序服务器到外部系统的入站和出站连接。它支持池、身份验证、事务等(数据库和JMS代理是通过JCA连接器访问的,顺便说一句)。
然而,编写这样的适配器可能相当困难。也许研究一种轻量级方法,其中通用池库(也许您在 commons-pool 或 c3p0 中发现一些有趣的东西)可能会更容易。
另请参阅有关 TCP 连接池的此答案。
The "right" way to do this would be to write a JCA connector for your external server. JCA is part of the Java EE stack, and is meant exactly for that: to provide inbound and outbound connectivity from the application server to external system. It supports pooling, authentication, transaction, etc. (Database and JMS broker are accesss through JCA connectors, btw).
Writing such an adapter can however be quite hard. Maybe investigate a lightweight approach which a generic pooling library (maybe you find something interesting in commons-pool, or c3p0) may be easier.
Have a look also at this answer about TCP connection pooling.