WebSphere MQ connection pooling with Tomcat

后端 未结 2 1909
天涯浪人
天涯浪人 2021-01-03 08:18

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

We are migrating a legacy Tomcat web application from WebSphere

2条回答
  •  情话喂你
    2021-01-03 08:59

    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.

    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:

    
    

    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 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;
                }
            }
    

提交回复
热议问题