如何在独立的 Java 应用程序中池化 JMS 连接?

发布于 2024-12-27 16:57:45 字数 204 浏览 6 评论 0原文

我们正在开发一个IBM WebSphere MQ应用程序,我们使用JMS API来操作消息。但是我们有一个问题,连接需要太多时间,并且我们想要池化 JMS 连接,因为它是一个独立的应用程序,我们没有应用程序容器来提供 JNDI 或池化服务。那么有没有办法解决这个问题呢?对于 JDBC,我们可以使用 DBCP 或 c3p0 来归档池数据源,在 JMS 中,是否有类似的项目可以池 JMS 连接?

We are working on an IBM WebSphere MQ application, and we use JMS API to operate the message. But we have a problem that the connection takes too much time, and we want to pool the JMS connection, for it's a standalone application, we have no application container to provide JNDI or pooling service. So is there a solution to resolve this? For JDBC we can use DBCP or c3p0 to archive pooling datasource, in JMS, is there any similar project that can pool JMS connections?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

在梵高的星空下 2025-01-03 16:57:45

过去,JMS MQConnectionFactory 内置了池,但似乎在版本中7、已删除。

在早期版本的 WebSphere 中设置 ConnectionPooling 的使用
JMS 的 MQ 类。保留此方法是为了兼容
较旧的 MQJMS 应用程序,但是,因为此连接池
功能已从版本 7 中删除,设置此属性
不会有任何影响。

如果没有其他任何东西,您可以使用 Apache Commons Pool。与 DBCP(使用 Pool)的想法相同,但适用于非 JDBC 对象。

It used to be that the JMS MQConnectionFactory had pooling built in, but it seems that in version 7, it has been removed.

Set the use of ConnectionPooling in earlier versions of the WebSphere
MQ classes for JMS. This method is retained for compatibility with
older MQJMS applications, but, because this Connection Pooling
functionality has been removed from version 7, setting this property
will have no effect.

In the absence of anything else, you can use Apache Commons Pool. Same idea as DBCP (which uses Pool) but for non JDBC objects.

萌能量女王 2025-01-03 16:57:45

Spring 的 CachingConnectionFactory 非常适合此用例。
https://stackoverflow.com/a/31119435/1765341 中的这个答案解释了如何在 Tomcat 中执行此操作,但是那里的代码可以轻松地适应 Java 独立应用程序。这应该比编写 Apache Commons Pool 实现更容易(并且更不容易出错)。

Spring's CachingConnectionFactory works well for this use case.
This answer in https://stackoverflow.com/a/31119435/1765341 explains how to do this in Tomcat, but the code there can easily be adapted for Java standalone applications. This should be much easier (and less error prone) than writing an Apache Commons Pool implementation.

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