0
votes

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>
1
You can use Spring profiles to remove the problematic bean in the test enviroment. spring.io/blog/2011/02/11/spring-framework-3-1-m1-released See after "Enter bean definition profiles"Evgeni Dimitrov
Here is another link that also refers what Evgeni menitioned using profiles for conditional startup: stackoverflow.com/questions/8279270/…Display Name is missing

1 Answers

0
votes

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>