与Tomcat的WebSphere MQ连接池 [英] WebSphere MQ connection pooling with Tomcat

查看:90
本文介绍了与Tomcat的WebSphere MQ连接池的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Tomcat有一个内置的JDBC连接池,但遗憾的是没有内置的JMS连接池。

Tomcat has a built-in JDBC connection pooling, but unfortunately no built-in JMS connection pooling.

我们正在从WebSphere MQ版本迁移旧的Tomcat Web应用程序
遗憾的是,WebSphere MQ 7中已删除了连接池,如下所述: http://www-01.ibm.com/support/docview.wss?uid=swg21665128

We are migrating a legacy Tomcat web application from WebSphere MQ version 6 to 7. Unfortunately, connection pooling has been removed in WebSphere MQ 7 as described here: http://www-01.ibm.com/support/docview.wss?uid=swg21665128

现在我们害怕如果我们只使用以下代码在Tomcat中配置MQ,我们将遇到麻烦:

Now we are afraid that we will run into troubles if we just use the following code for configuring MQ in Tomcat:

        <Resource name="jms/XXXQCF" auth="Container"
            type="com.ibm.mq.jms.MQQueueConnectionFactory" factory="com.ibm.mq.jms.MQQueueConnectionFactoryFactory"
            description="JMS Queue Connection Factory"
            HOST="xxx.com" PORT="1429" CHAN="XXX" TRAN="1"
            QMGR="XXX" />

我们担心的原因是在使用MQ 7时不会使用池化JMS提供程序。有关详细信息,另请参阅 http://activemq.apache.org/jmstemplate-gotchas.html

The reason for our concerns is that this will not use a pooled JMS provider when using MQ 7. For details, see also http://activemq.apache.org/jmstemplate-gotchas.html

我们看到的替代解决方案是:

Alternative solutions we see are:

1)使用Atomikos

1) Use of Atomikos

Atomikos有一个com.atomikos.jms.AtomikosConnectionFactoryBean,可以用来代替MQQueueConnectionFactory
但是当我们不需要XA时,使用XA事务管理器是一个巨大的开销

Atomikos has a com.atomikos.jms.AtomikosConnectionFactoryBean that can be used instead of MQQueueConnectionFactory But using an XA transaction manager is a huge overhead when we don't need XA

2)使用Spring的CachingConnectionFactory

2) Use Spring's CachingConnectionFactory

看起来是一个很好的解决方案,但不幸的是我们的遗留应用程序不使用Spring。
所以我们假设使用CachingConnectionFactory意味着相当多的努力。

looks like a good solution, but unfortunately our legacy application does not use Spring. So we assume that using CachingConnectionFactory would mean quite some effort.

3)使用Apache Commons Pool

3) Use Apache Commons Pool

看起来很有希望,但是为JMS正确实现它将需要一些良好的JMS知识

looks promising too, but implementing it correctly for JMS will require some good JMS knowledge

我们的问题:


  • 是否有一个JMS提供程序可用于包装MQQueueConnectionFactory,它将汇集连接,会话,生产者和消费者?

  • 是否有人成功实现其中一个我们在上面概述的替代解决方案?

推荐答案

正如Umapathy在选项3中提出的,我们现在选择使用Spring的CachingConnectionFactory的方法,它甚至适用于非Spring应用程序。您需要做的就是将Spring Jars添加到类路径中,并使用CachingConnectionFactory包装MQQueueConnectionFactory。

As proposed by Umapathy in option 3, we now opted for the approach using Spring's CachingConnectionFactory, and it works well even for a non-Spring application. All you need to do is add the Spring Jars to the classpath, and wrap the MQQueueConnectionFactory with a CachingConnectionFactory.

我们选择创建自己的Tomcat QueueConnectionFactoryFactory,使我们能够离开原始应用程序代码完全不受影响,您只需要使用以下XML定义从Tomcat配置文件(如上面的问题所示)替换原始MQ连接工厂:

We chose to create our own Tomcat QueueConnectionFactoryFactory that enables us to leave the original application code completely untouched, you just need to replace the original MQ connection factory from the Tomcat configuration file (shown above in the question) with the following XML definition:

<Resource name="jms/XXXQCF" auth="Container"
          type="org.springframework.jms.connection.CachingConnectionFactory"
          factory="at.rsf4j.core.utilities.RSFCachingMQQueueConnectionFactoryFactory"
          description="JMS Queue Connection Factory"
          HOST="xxx.com" PORT="1429" CHAN="XXX" TRAN="1"
          QMGR="XXX" />

以下是RSFCachingMQQueueConnectionFactoryFactory的(简化)代码(无错误检查):

Here is the (simplified) code (without error checking) for the RSFCachingMQQueueConnectionFactoryFactory:

public class RSFCachingMQQueueConnectionFactoryFactory implements ObjectFactory{

public Object getObjectInstance (Object obj, Name name, Context nameCtx, Hashtable<?,?> environment)
    throws NamingException {
            Reference ref = (Reference) obj;
            String beanClassName = ref.getClassName();
            Class<?> beanClass = Class.forName(beanClassName);
            if (CachingConnectionFactory.class.isAssignableFrom(beanClass)){
                MQQueueConnectionFactoryFactory cff = new MQQueueConnectionFactoryFactory();
                Reference mqReference = new Reference(
                        MQQueueConnectionFactory.class.getName());

                Enumeration<RefAddr> allAddrs = ref.getAll();
                while (allAddrs.hasMoreElements()){
                    mqReference.add(allAddrs.nextElement());
                }

                MQQueueConnectionFactory cf = (MQQueueConnectionFactory)cff.getObjectInstance(mqReference, name, nameCtx, environment);
                CachingConnectionFactory ccf = (CachingConnectionFactory)beanClass.newInstance();
                ccf.setTargetConnectionFactory(cf);
                return ccf;
            }
        }

这篇关于与Tomcat的WebSphere MQ连接池的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆