简体   繁体   中英

JMS automatically reconnecting to TOPIC

I have two apps one app is publishing to a topic and another app is reading from that topic. We had a scenario where a queuemanager went down and then was available again. The publisher (without a restart) carries on working fine after the queuemanager restarts, but the topic consumer does not recieve the new messages from the publisher until it is restarted. Is there some configuration that can be setup on the topic consumer to refresh its connection somehow? We are using java / spring / spring integration over IBM MQ. The following is the configuration of our consumer.

<bean id="jmsAlertsServiceMessageListener" class="org.springframework.jms.listener.DefaultMessageListenerContainer">
    <property name="connectionFactory" ref="alertConnectionFactory"/>
    <property name="destination" ref="alertsServiceTopic"/>
    <property name="autoStartup" value="false"/>
    <property name="clientId" value="${ps.Alert.clientId}"/>
    <property name="taskExecutor" ref="jmsTaskExecutor"/>
    <property name="subscriptionDurable" value="true"/>
    <property name="pubSubDomain" value="true"/>
    <property name="messageSelector" value="AlertState = 'RESOLVED'"/>
    <property name="messageListener" ref="alertsMessageListener"/>
    <property name="durableSubscriptionName" value="replay"/>
    <property name="recoveryInterval" value="30000"/>
</bean>

<bean id="alertConnectionFactory" class="com.ibm.mq.jms.MQConnectionFactory"  >
    <property name="transportType" value="1" />   
    <property name="queueManager" value="${alert.mq.qm}" />
    <property name="hostName" value="${alert.mq.host}" />
    <property name="port" value="${alert.mq.port}" />
    <property name="channel" value="${alert.mq.channel}" />     
    <property name="SSLCipherSuite" value="SSL_RSA_WITH_RC4_128_SHA" />        
    <property name="brokerPubQueue" value="${alert.mq.topic_connection_factory_broker_pub_queue}"/>
    <property name="brokerQueueManager" value="${alert.mq.topic_connection_factory_broker_queue_manager}"/>
    <property name="providerVersion" value="${alert.mq.topic_connection_factory_provider_version}"/>
    <property name="brokerVersion" value="1"/>       
    <property name="messageSelection" value="1"/>     
</bean>

<bean id="alertsServiceTopic" class="com.ibm.mq.jms.MQTopic">
    <constructor-arg value="${alert.mq.topic}" />
    <property name="brokerDurSubQueue" value="${alert.mq.queue}"/>        
    <property name="brokerVersion" value="1"/>          
</bean>

<bean id="alertsMessageListener" class="org.springframework.integration.jms.ChannelPublishingJmsMessageListener">
    <property name="requestChannel" ref="alertsJmsInputChannel"/>
</bean>

<bean id="jmsTaskExecutor" class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor">
    <property name="corePoolSize" value="1"/>
    <property name="maxPoolSize" value="1"/>
    <property name="waitForTasksToCompleteOnShutdown" value="true"/>
    <property name="daemon" value="false"/>
    <property name="threadNamePrefix" value="jmsInbound-"/>
    <property name="queueCapacity" value="3"/>
    <!-- Discard any task that gets rejected. -->
    <property name="rejectedExecutionHandler">
        <bean class="java.util.concurrent.ThreadPoolExecutor$DiscardPolicy"/>
    </property>
</bean>

The DefaultMessageListenerContainer will automatically reconnect according to the recoveryInterval .

Turn on DEBUG (or even TRACE) logging to figure out what's happening.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM