how to configure (spring) JMS connection Pool for WMQ

 ̄綄美尐妖づ 提交于 2019-12-01 12:42:34

In general:

  • do not use QueueConnectionFactory or TopicConnectionFactory, as ConnectionFactory (JMS 1.1) is replacement for both
  • Each ConnectionFactory from v7 WMQ JMS client jars provide caching logic on each own so in general you don't need CachingConnection Factory.

Now try it this way:

<bean id="mqConnectionFactory" class="com.ibm.mq.jms.MQConnectionFactory"
  p:queueManager="${QM_NAME}"
  p:hostName="${QM_HOST_NAME}"
  p:port="${QM_HOST_PORT}"
  p:channel="${QM_CHANNEL}"
  p:clientID="${QM_CLIENT_ID}">
  <property name="transportType">
    <util:constant static-field="com.ibm.msg.client.wmq.WMQConstants.WMQ_CM_CLIENT" />
  </property>
</bean>

<bean id="userConnectionFactory" class="org.springframework.jms.connection.UserCredentialsConnectionFactoryAdapter"
  p:targetConnectionFactory-ref="mqConnectionFactory"
  p:username="${QM_USERNAME}"
  p:password="${QM_PASSWORD}" />

<!-- this will work -->
<bean id="connectionFactory" class="org.springframework.jms.connection.CachingConnectionFactory"
  p:targetConnectionFactory-ref="userConnectionFactory"
  p:cacheConsumers="true"
  p:reconnectOnException="true" />

Of course you can cache sessions instead of consumers if you want it that way. By my experience WMQ session caching is measurable performance improvement but only if you are limited on CPU power on WMQ machine or by actual message throughput; both situations are rare in majority of world applications. Caching consumers avoids excessive MQ OPEN calls which is expensive operation on WMQ so it helps too.

My rule of the thumb is consumer + session caching performance benefit is equal to 1/2 of performance benefit of connection caching and usually not wort of pursuing in your everyday JEE stack unless you are hardware limited.

Since WMQ v7, asynchronous consumers are realy realy fast with literally no CPU overhead when compared to spring MC, and are preferred way of consuming messages if you are HW limited. Most of the days I still use Spring as I prefer its easy-going nature.

Hope it helps.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!