使用DefaultMessageListenerContainer和CachingConnectionFactory

时间:2019-03-06 22:52:52

标签: spring-integration spring-jms

在我们的应用程序中,我们将SingleConnectionFactory与DefaultMessageListenerContainer一起使用,这是从IBM MQ服务器使用的,性能方面,该应用程序运行良好,但是在MQ端,我们的应用程序随机打开了太多新连接。这是我们当前的配置。

<bean id="primary" class="org.springframework.jms.listener.DefaultMessageListenerContainer">
        <property name="connectionFactory" ref="primaryConnectionFactory"/>
        <property name="destinationName" value="CCS.COMM.FEED.FULFILLMENT"/>
        <property name="transactionManager" ref="primaryTransactionManager" />   
        <property name="sessionTransacted" value="true" />   
        <property name="concurrentConsumers" value="10" />
        <property name="maxConcurrentConsumers" value="10" />
        <property name="autoStartup" value="true" />
        <property name="recoveryInterval" value="60000" />
        <property name="cacheLevelName" value="CACHE_CONSUMER" />        
    </bean>  

<bean id="primaryConnectionFactory" class="org.springframework.jms.connection.SingleConnectionFactory">
      <property name="targetConnectionFactory" ref="primaryRawInputConnectionFactory" />
      <property name="reconnectOnException" value="true" />
   </bean>

我们使用cachingConnectionFactory修复了与MQ的泄漏连接问题,但是使用以下设置会降低性能。

<bean id="inboundConnectionFactory" class="org.springframework.jms.connection.CachingConnectionFactory">
      <property name="targetConnectionFactory" ref="inboundConnectionFactoryAdapter" />
      <property name="sessionCacheSize" value="10" />
   </bean>

    <bean id="jmsTransactionManager" class="org.springframework.jms.connection.JmsTransactionManager">
        <property name="connectionFactory" ref="inboundConnectionFactory" />
    </bean>

    <bean id="inboundListenerContainer" class="org.springframework.jms.listener.DefaultMessageListenerContainer">
        <property name="connectionFactory" ref="inboundConnectionFactory"/>
        <property name="destinationName" value="CCS.COMM.FEED.FULFILLMENT"/> 
        <property name="transactionManager" ref="jmsTransactionManager" />   
        <property name="sessionTransacted" value="true" />   
        <property name="concurrentConsumers" value="10" />
        <property name="maxConcurrentConsumers" value="10" />
        <property name="autoStartup" value="true" />

请您提出我们可以采取哪些措施来改善性能...

2 个答案:

答案 0 :(得分:0)

尝试使用此方法,而不是缓存或单次操作:

<bean id="connectionFactory" class="org.springframework.jms.connection.DelegatingConnectionFactory">
    <property name="targetConnectionFactory" ref="primaryRawInputConnectionFactory" />
    <property name="shouldStopConnections" value="true"/>
</bean>

答案 1 :(得分:0)

这是primaryRawInputConnectionFactory的

 <bean id="primaryRawInputConnectionFactory" class="org.springframework.jms.connection.UserCredentialsConnectionFactoryAdapter">
      <property name="targetConnectionFactory" ref="innboundTargetConnectionFactory"/>
      <property name="username" value="${jms.input.userid}" />
      <property name="password" value="${jms.input.password}" />
   </bean>

   <bean id="innboundTargetConnectionFactory" class="org.springframework.jndi.JndiObjectFactoryBean">
      <property name="jndiTemplate" ref="inboundJmsJndiTemplate"/>
      <property name="jndiName" value="${jms.input.connection.factory.name}"/>
      <property name="lookupOnStartup" value="false"/>
      <property name="proxyInterface" value="javax.jms.ConnectionFactory"/>
   </bean>

   <bean id="inboundJmsJndiTemplate" class="org.springframework.jndi.JndiTemplate">
      <property name="environment">
         <props>
            <prop key="java.naming.factory.initial">com.ibm.mq.jms.context.WMQInitialContextFactory</prop>
            <prop key="java.naming.provider.url">${jms.input.server.url}</prop>
            <prop key="java.naming.security.principal">${jms.input.userid}</prop>
            <prop key="java.naming.security.credentials">${jms.input.password}</prop>
         </props>
      </property>
   </bean>