简体   繁体   中英

How to disable JMS spring listener in test evnvironment

I am using spring JMSTemplate to connect to a queue on a different weblogic domain. I wired all the components like jndiTemplate, connectionfactory, destination etc in the Spring config. Messages are handled by a simple implementation of MessageListener.

It all works fine. But when I try to deploy this application where the destination is not available, deployment fails. this is very important for me as we dont have JMS infrastructure in some of our environments.
I tried with lookupOnStartup=false on all the components and tried injecting them into DMLC based on a environment variable. But the issue is, the listener doesnt seem to be starting up. All the messages are left in the queue.

Any help is highly appreciated.

Spring-config:

<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>

You can set autoStartup to false. This property value can be externalized in a properties files.

<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>

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