【问题标题】:How to disable JMS spring listener in test evnvironment如何在测试环境中禁用 JMS spring 监听器
【发布时间】:2014-01-24 03:56:05
【问题描述】:

我正在使用 spring JMSTemplate 连接到不同 weblogic 域上的队列。 我在 Spring 配置中连接了所有组件,如 jndiTemplate、connectionfactory、destination 等。 消息由 MessageListener 的简单实现处理。

一切正常。但是,当我尝试在目的地不可用的地方部署此应用程序时,部署失败。这对我来说非常重要,因为我们的某些环境中没有 JMS 基础架构。
我尝试在所有组件上使用 lookupOnStartup=false,并尝试根据环境变量将它们注入 DMLC。但问题是,听众似乎没有启动。所有消息都留在队列中。

非常感谢任何帮助。

弹簧配置:

<bean id="jndiTemplate" class="org.springframework.jndi.JndiTemplate">
    <property name="environment">
        <props>
            <prop key="java.naming.factory.initial">weblogic.jndi.WLInitialContextFactory</prop>
            <prop key="java.naming.provider.url">t3://wp2128.xyz.int:7001</prop>
            <prop key="java.naming.security.authentication">none</prop>
            <prop key="java.naming.security.principal"></prop>
            </props>    
    </property>
</bean>
<bean id="connectionFactory" class="org.springframework.jndi.JndiObjectFactoryBean" >
    <property name="jndiTemplate" ref="jndiTemplate" />
    <property name="jndiName" value="jms/connectionFactory" />
</bean>
<bean id="destination" class="org.springframework.jndi.JndiObjectFactoryBean">
    <property name="jndiTemplate" ref="jndiTemplate" />
    <property name="jndiName" value="jms/testQueue" />
</bean>


<bean id="simpleConsumer"
    class="org.springframework.jms.listener.DefaultMessageListenerContainer">
    <property name="concurrentConsumers" value="5" />
    <property name="connectionFactory" ref="connectionFactory" />
    <property name="destination" ref="destination" />
    <property name="messageListener" ref="simpleMessageListener" />
</bean>

【问题讨论】:

标签: java spring spring-mvc jms weblogic


【解决方案1】:

您可以将 autoStartup 设置为 false。此属性值可以在属性文件中外部化。

<bean id="simpleConsumer"
    class="org.springframework.jms.listener.DefaultMessageListenerContainer">
    <property name="concurrentConsumers" value="5" />
    <property name="connectionFactory" ref="connectionFactory" />
    <property name="destination" ref="destination" />
    <property name="messageListener" ref="simpleMessageListener" />
   <property name="autoStartup" value="false"/>
</bean>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-26
    • 1970-01-01
    • 2023-03-23
    • 2019-06-22
    相关资源
    最近更新 更多