是否有“套接字连接池”? Java EE 应用程序有哪些类型?

发布于 2024-08-23 13:19:17 字数 327 浏览 8 评论 0原文

我正在编写 JAX-RS Web 服务。它通过以下方式响应客户端调用:

  1. 从数据库检索一些信息
  2. 调用外部服务器

对于 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:

  1. Retrieving some info from a database
  2. 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一绘本一梦想 2024-08-30 13:19:17

执行此操作的“正确”方法是为外部服务器编写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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文