【问题标题】:Spring Integration auto reconnect to IBM MQ thru JBOSS Resource AdapterSpring Integration 通过 JBOSS 资源适配器自动重新连接到 IBM MQ
【发布时间】:2016-01-23 08:16:12
【问题描述】:

我们在我们的项目中使用 Spring Integration,并且我们有一个要求,如果 IBM MQ 出现故障,那么我们必须在它启动时自动连接到 IBM MQ。我们使用org.springframework.jms.listener.DefaultMessageListenerContainer 类的recoveryInterval 选项完成了这个实现。我们已经给出了恢复间隔值来尝试恢复 MQ 连接。但是 MQ 重启后它并没有恢复连接。以下是我现有的配置:

       <jms:message-driven-channel-adapter id="adapterId" channel="raw-channel" container="messageListenerContainer" />


        <bean id="messageListenerContainer"  class="org.springframework.jms.listener.DefaultMessageListenerContainer">
                <property name="connectionFactory" ref="customQueueCachingConnectionFactory" />
                <property name="destination" ref="requestQueue" />
                <property name="recoveryInterval" value="60000" />
            </bean>

    Below is the Current Connection Factory :
    <bean id="queueCachingConnectionFactory"
            class="org.springframework.jms.connection.CachingConnectionFactory">
            <property name="targetConnectionFactory" ref="queueConnectionFactory" />
            <property name="sessionCacheSize" value="10" />
            <property name="cacheProducers" value="false" />
    <!--        <property name="reconnectOnException" value="true" /> -->
    <!--        <property name="exceptionListener" ref="MQExceptionListener"></property> -->
        </bean>

        <jee:jndi-lookup id="queueConnectionFactory" jndi-name="MQConnectionFactory"
            expected-type="javax.jms.ConnectionFactory" lookup-on-startup="true"></jee:jndi-lookup>


        <jee:jndi-lookup id="queue" jndi-name="Queue"
            expected-type="javax.jms.Queue" lookup-on-startup="true"/>

ERROR [task-scheduler-4] LoggingHandler:145 -org.springframework.jms.IllegalStateException: MQJCA1019: The connection is closed.; nested exception is com.ibm.msg.client.jms.DetailedIllegalStateException: MQJCA1019: The connection is closed.
    The application attempted to use a JMS connection after it had closed the connection.
    Modify the application so that it closes the JMS connection only after it has finished using the connection.

提前致谢!!

【问题讨论】:

  • 您也应该分享ConnectionFactory 配置。另外,也分享有关此事的日志。如果您说“通过 JBOSS 资源适配器”,那么问题可能就在那里,而不是在 Spring...
  • @ArtemBilan:你能帮我解决上述问题吗

标签: spring-integration ibm-mq spring-jms


【解决方案1】:

默认的消息监听容器应该引用缓存连接工厂:

 <!-- caching connection factory fascade, also implements exception listener -->
<bean id="cachingConnectionFactory" class="org.springframework.jms.connection.CachingConnectionFactory">
   <property name="targetConnectionFactory" ref="connectionFactory"/>
   <property name="sessionCacheSize" value="10"/>
   <property name="reconnectOnException" value="true"/>
</bean>

<!-- this is the Message Driven POJO (MDP) -->
<bean id="messageDrivenPOJO" class="com.redhat.gss.spring.MessageDrivenPOJO" />

<!-- The message listener container -->
<bean id="messageListener" class="org.springframework.jms.listener.DefaultMessageListenerContainer">
   <property name="sessionTransacted" value="true"/>
   <property name="concurrentConsumers" value="1"/>
   <property name="cacheLevelName" value="CACHE_CONSUMER"/>                
   <property name="receiveTimeout" value="10000"/>
   <property name="sessionAcknowledgeMode" value="2"/>
   <property name="messageListener" ref="messageDrivenPOJO"/>
   <property name="connectionFactory" ref="cachingConnectionFactory"/>
   <property name="exceptionListener" ref="cachingConnectionFactory"/>
   <property name="destination" ref="jbossQueue"/>
</bean>

【讨论】:

    猜你喜欢
    • 2015-11-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-07-17
    • 2021-07-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-29
    相关资源
    最近更新 更多