Announcement Announcement Module
Collapse
No announcement yet.
WMQ & Spring JmsTemplate & Pooled ConnectionFactory Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • WMQ & Spring JmsTemplate & Pooled ConnectionFactory

    Currently I have implemented a WMQ application underneath Spring framework : I use DefaultMessageListenerContainer for inbounding message processing, and JmsTemplate for outbounding message processing. I use Jotm for JTA transaction, which all seems fine except one major problem with JmsTemplate : it is an expensive operation to create connection, seesion, queueproducer each time when a message is sent, which is unacceptable in our case.

    Do you know any similar pooledConnectionFactory for WMQ 6.0 so I can config that to maintain a pool of connection, or even a pool of sessions, etc.

    I notice you wrote jencks AMQPool for ActiveMQ. Are there similar component for WMQ.

    Anyone there fr a dvice

  • #2
    WMQ configuration

    Here are the configuration details:
    Code:
    <bean id="internalJmsFactory" class="com.ibm.mq.jms.MQQueueConnectionFactory">
        <property name="queueManager" value ="${queueManager}"/>
        <property name="port" value ="${port}"/>
        <property name="hostName" value ="${hostName}"/>
        <property name="transportType" value ="${transportType}"/>
        <property name="channel" value ="${channel}"/>
      </bean> 
     
      <bean id="jmsConnectionFactory"
            class="org.springframework.jms.connection.UserCredentialsConnectionFactoryAdapter">
            <property name="targetConnectionFactory" ref="internalJmsFactory"/>
            <property name="username" value="${username}"/>
            <property name="password" value="${password}"/>
      </bean>  
        <!-- JMS queus  -->
    
      <bean id="outgoingQueue" class="com.ibm.mq.jms.MQQueue" autowire="constructor">
        <constructor-arg>
          <value>queue:///${outgoingqueuename}</value>
        </constructor-arg>
      </bean>
       <bean id="errorOutgoingQueue" class="com.ibm.mq.jms.MQQueue" autowire="constructor">
        <constructor-arg>
          <value>queue:///${error_outgoingqueuename}</value>
        </constructor-arg>
      </bean>
      <bean id="incomingQueue" class="com.ibm.mq.jms.MQQueue" autowire="constructor">
        <constructor-arg>
          <value>queue:///${incomingqueuename}</value>
        </constructor-arg>
      </bean>
       <bean id="errorIncomingQueue" class="com.ibm.mq.jms.MQQueue" autowire="constructor">
        <constructor-arg>
          <value>queue:///${error_incomingqueuename}</value>
        </constructor-arg>
      </bean>
     <bean id="jotm" class="org.springframework.transaction.jta.JotmFactoryBean"/>
    
     <bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager">
        <property name="userTransaction"><ref local="jotm"/></property>
     </bean> 
     <bean id="doMessageConverter" class="com.arcinnovations.ami.comms.messaging.DOMessageConverter"/>
     <bean id="dtMessageConverter" class="com.arcinnovations.ami.comms.messaging.DTMessageConverter"/>
      <!-- Spring JMS Template -->
      <bean id="outgoingTemplate" abstract ="true" class="org.springframework.jms.core.JmsTemplate">
          <property name="connectionFactory">
                <ref bean="jmsConnectionFactory"/>
          </property>
          <property name="defaultDestination">
                <ref bean="outgoingQueue"/>
          </property>  
          <property name="messageConverter">
                <ref bean="dtMessageConverter"/>
          </property>
          <property name="explicitQosEnabled" value = "true"/>
          <property name="deliveryMode" value = "${deliveryMode}"/>
      </bean>
      <bean id="errorOutgoingTemplate" class="org.springframework.jms.core.JmsTemplate">
          <property name="connectionFactory">
                <ref bean="jmsConnectionFactory"/>
          </property>
          <property name="defaultDestination">
                <ref bean="errorOutgoingQueue"/>
          </property>  
          <property name="messageConverter">
                <ref bean="dtMessageConverter"/>
          </property>
          <property name="priority" value = "${normalPriority}"/>
          <property name="explicitQosEnabled" value = "true"/>
          <property name="deliveryMode" value = "${deliveryMode}"/>
      </bean>
      <bean id="lowOutgoingTemplate" parent="outgoingTemplate">     
          <property name="priority" value = "${lowPriority}"/>
      </bean>
       <bean id="normalOutgoingTemplate" parent="outgoingTemplate">   
          <property name="priority" value = "${normalPriority}"/>
      </bean>
      <bean id="highOutgoingTemplate" parent="outgoingTemplate">   
          <property name="priority" value = "${highPriority}"/>
      </bean>
      <bean id="incomingTemplate" abstract="true" class="org.springframework.jms.core.JmsTemplate">
          <property name="connectionFactory">
                <ref bean="jmsConnectionFactory"/>
          </property>
          <property name="defaultDestination">
                <ref bean="incomingQueue"/>
          </property>  
          <property name="messageConverter">
                <ref bean="doMessageConverter"/>
          </property>
          <property name="explicitQosEnabled" value = "true"/>
          <property name="deliveryMode" value = "${deliveryMode}"/>
      </bean>
       <bean id="errorIncomingTemplate" class="org.springframework.jms.core.JmsTemplate">
          <property name="connectionFactory">
                <ref bean="jmsConnectionFactory"/>
          </property>
          <property name="defaultDestination">
                <ref bean="errorIncomingQueue"/>
          </property>  
          <property name="messageConverter">
                <ref bean="doMessageConverter"/>
          </property>
          <property name="priority" value = "${normalPriority}"/>
          <property name="explicitQosEnabled" value = "true"/>
          <property name="deliveryMode" value = "${deliveryMode}"/>
      </bean>
      <bean id="lowIncomingTemplate" parent="incomingTemplate">     
          <property name="priority" value = "${lowPriority}"/>
      </bean>
      <bean id="normalIncomingTemplate" parent="incomingTemplate">     
          <property name="priority" value = "${normalPriority}"/>
      </bean>
      <bean id="highIncomingTemplate" parent="incomingTemplate">     
          <property name="priority" value = "${highPriority}"/>
      </bean>  
       <bean id="abstractListenerContainer" abstract="true" class="org.springframework.jms.listener.DefaultMessageListenerContainer">
            <property name="connectionFactory">
                <ref bean="jmsConnectionFactory"/>
            </property>
            <property name="concurrentConsumers" value="${concurrentConsumers}"/>
            <property name="maxConcurrentConsumers" value="${maxConcurrentConsumers}"/>
            <property name="transactionManager" ref="transactionManager"/> 
            <property name="sessionTransacted" value="${sessionTransacted}"/> 
            <property name="recoveryInterval" value="${recoveryInterval}"/> 
             <property name="cacheLevel" value="${cacheLevel}"/> 
            
      
        </bean> 
    <bean id="dtMessageSender" class="com.arcinnovations.ami.comms.messaging.DTMessageSender" >
            <property name="lowPriorityTemplate">
                <ref bean="lowOutgoingTemplate"/>
            </property>
            <property name="normalPriorityTemplate">
                <ref bean="normalOutgoingTemplate"/>
            </property>
            <property name="highPriorityTemplate">
                <ref bean="highOutgoingTemplate"/>
            </property>
            <property name="errorQueueTemplate">
                <ref bean="errorOutgoingTemplate"/>
            </property>
              
        </bean>
        
         <bean id="incomingQueueListener" class="com.arcinnovations.ami.comms.messaging.DOMessageListener">
            <property name="service">
                <ref bean="commsManagerService"/>
            </property>
            <property name="converter">
                <ref bean="doMessageConverter"/>
            </property>
         </bean>
          <bean id="exceptionListener" class="com.arcinnovations.ami.comms.messaging.JMSExceptionListener" >
            <property name="service">
                <ref bean="commsManagerService"/>
            </property>
        </bean>  
         <bean id="incomingQueueContainer" parent="abstractListenerContainer">   
            
            <property name="messageListener">
                <ref bean="incomingQueueListener"/>
            </property>
            <property name="exceptionListener">
                <ref bean="exceptionListener"/>
            </property>     
            <property name="destination">
                <ref bean="incomingQueue"/>
            </property>      
      
        </bean>

    Comment


    • #3
      Thanks for posting your code

      alicexc, Thanks for posting your configuration code. This is really helpful.

      Really appreciate this.

      rsrch

      Comment


      • #4
        mq java

        According to IBM doc "WebSphere MQ Using Java", available at http://www-306.ibm.com/software/inte...library6x.html,

        the following line activates the build-in connection pool:

        MQPoolToken token=MQEnvironment.addConnectionPoolToken();

        and this deactivates it

        MQEnvironment.removeConnectionPoolToken(token);

        I've not verified if it works with JMS. I am interested in what you might find out.

        Comment

        Working...
        X