根据来自数据库的标志打开/关闭IBM MQ侦听器

问题描述 投票:0回答:1

这是一个现有的整体应用程序,需要进行修复,而无需对安装程序进行重大更改。

项目设置:项目1(配置)->存在所有mq-xml文件的位置(例如-ibm_mq_config.xml)

例如-dev_bm_mq.xml的内容

$ {hname}$ {port}$ {qmgr}1个

<!-- JMS Queue Connection Factory -->
<bean id="jmsQueueIdsConnectionFactory"
    class="org.springframework.jms.connection.SingleConnectionFactory">
    <property name="targetConnectionFactory">
        <ref bean="mqIdsConnectionFactory" />
    </property>

</bean>


<!-- JMS Destination Resolver -->
<bean id="jmsDestinationResolver"
    class="org.springframework.jms.support.destination.DynamicDestinationResolver">
</bean>


<!-- JMS Queue Template -->
<bean id="jmsQueueIdsTemplate" class="org.springframework.jms.core.JmsTemplate">
    <property name="connectionFactory">
        <ref bean="jmsQueueIdsConnectionFactory" />
    </property>
    <property name="defaultDestinationName">
        <value>${myQUEUE}</value>
    </property>
    <property name="pubSubDomain">
        <value>false</value>
    </property>
    <property name="receiveTimeout">
        <value>20000</value>
    </property>
</bean>  

<bean id="jmsContainer"
    class="org.springframework.jms.listener.DefaultMessageListenerContainer">
    <property name="connectionFactory" ref="jmsQueueConnectionFactory" />
    <property name="destinationName">
        <value>${myQUEUE}</value>
    </property>
    <property name="messageListener" ref="simpleMessageListener" />
    <property name="concurrentConsumers" value="2" />
    <property name="maxConcurrentConsumers" value="3" />
    <property name="idleTaskExecutionLimit" value="4" />
    <property name="maxMessagesPerTask" value="4" />
    <property name="receiveTimeout" value="5000" />
    <property name="recoveryInterval" value="5000" />
    <property name="sessionTransacted" value="true" />
</bean> 

**** Project B(App)****

从项目配置中加载spring xml,如下所示:WebContent / WEB-INF / spring / sprint-context.xm

<import resource="classpath*:com/my/package/${config.env}-${config-broker}.mq.xml"

public class TestMessageListener implements MessageListener {

        public void onMessage(Message message) {
          //process the message
      }
    }

服务器启动时,它可以启动服务器并设置侦听器而没有任何问题。

以上设置问题:当我们水平缩放应用程序(添加几个节点)时,它给出了我要解决的最大通道问题。

要求:基于数据库表,我想动态关闭几个节点上的mq侦听器。或当我水平缩放应用程序时。

例如-表格:mq-config

|host|broker|flag
-----------------------------
|qa5|ibm|false
|qa2|ibm|true

因此,我希望qa5上的mq监听器不启动,而qa2上的mq监听器启动并监听队列。另外,我想即时停止/启动监听器(仅通过更新数据库)

问题-关于如何在不重写整个设置的情况下实现上述用例的任何想法。

spring-mvc ibm-mq spring-jms message-listener
1个回答
0
投票

注入侦听器容器(例如@Autowired)。

然后

jmsContainer.stop();
jmsContainer.shutdown();

...

jmsContainer.initialize();
jmsContainer.start();

您还可以将autoStartup属性设置为false,以防止在应用程序初始化期间启动容器(但不要在第一个initialize()之前调用start()-仅在调用shutdown()之后才调用。

© www.soinside.com 2019 - 2024. All rights reserved.