8

While running integration tests in my application, I get below error messages in the failsafe test report for one of my integration test:

listener.DefaultMessageListenerContainer,WARN,Setup of JMS message listener invoker failed for destination 'jms/myapp.OneWorker' - trying to recover. Cause: Destination [jms/myapp.OneWorker] not found in JNDI; nested exception is javax.naming.NameNotFoundException: jms/myapp.OneWorker

Below is my configuration detail:

<bean id="jndiTemplate" class="org.springframework.jndi.JndiTemplate">
    <property name="environment">
        <props>
            <prop key="java.naming.factory.initial">
                org.apache.activemq.jndi.ActiveMQInitialContextFactory</prop>
            <prop key="java.naming.provider.url">vm://localhost:0</prop>
            <prop key="java.naming.security.principal">system</prop>
            <prop key="java.naming.security.credentials">system</prop>
        </props>
    </property>
</bean>

<bean id="jndiQueueConnectionFactory" class="org.springframework.jndi.JndiObjectFactoryBean">
    <property name="jndiTemplate" ref="jndiTemplate" />
    <property name="jndiName" value="jmsFactory" />
</bean>

<bean id="queueConnectionFactory"
    class="org.springframework.jms.connection.CachingConnectionFactory">
    <property name="targetConnectionFactory" ref="jndiQueueConnectionFactory" />
    <property name="sessionCacheSize" value="1" />
</bean>

<bean id="destinationResolver"
    class="org.springframework.jms.support.destination.JndiDestinationResolver">
    <property name="jndiTemplate" ref="jndiTemplate" />
    <property name="cache" value="true" />
    <property name="fallbackToDynamicDestination" value="false" />
</bean>

<bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate">
    <property name="connectionFactory" ref="queueConnectionFactory" />
    <property name="destinationResolver" ref="destinationResolver" />
    <property name="pubSubDomain" value="true" />
</bean>

<bean id="workerOneListener" class="com.org.myapp.workflow.WorkerOne">
    <property name="workflowManager" ref="workflowManagerImpl" />
</bean>

<jms:listener-container connection-factory="queueConnectionFactory"
    destination-resolver="destinationResolver" concurrency="3">
    <jms:listener destination="jms/myapp.OneWorker" ref="workerOneListener" />
    <jms:listener destination="jms/myapp.TwoWorker" ref="workerOneListener" />
    <jms:listener destination="jms/myapp.ThreeWorker" ref="workerOneListener" />
</jms:listener-container>  

The integration tests have a base class which creates the spring application contexts and is shared by all the other integration tests in the module.
I enabled logging with debug level and got below error messages:

2014-01-29 11:13:24,connection.CachingConnectionFactory,DEBUG,Closing cached Session:     ActiveMQSession {id=ID:CHN03876623-56121-1390973978321-2:0:70,started=true}
2014-01-29 11:13:24,connection.CachingConnectionFactory,DEBUG,Closing cached Session: ActiveMQSession {id=ID:CHN03876623-56121-1390973978321-2:0:70,started=true}
2014-01-29 11:13:24,connection.CachingConnectionFactory,DEBUG,Creating cached JMS Session for mode 1: ActiveMQSession {id=ID:CHN03876623-56121-1390973978321-2:0:71,started=true}
2014-01-29 11:13:24,jndi.JndiTemplate,DEBUG,Looking up JNDI object with name [jms/myapp.OneWorker]
2014-01-29 11:13:24,destination.JndiDestinationResolver,DEBUG,Destination [jms/myapp.OneWorker] not found in JNDI
javax.naming.NameNotFoundException: jms/myapp.OneWorker
    at org.apache.activemq.jndi.ReadOnlyContext.lookup(ReadOnlyContext.java:225)
    at javax.naming.InitialContext.lookup(InitialContext.java:392)
    at org.springframework.jndi.JndiTemplate$1.doInContext(JndiTemplate.java:154)
    at org.springframework.jndi.JndiTemplate.execute(JndiTemplate.java:87)
    at org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:152)
    at org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:179)
    at org.springframework.jndi.JndiLocatorSupport.lookup(JndiLocatorSupport.java:95)
    at org.springframework.jms.support.destination.JndiDestinationResolver.resolveDestinationName(JndiDestinationResolver.java:111)
    at org.springframework.jms.support.destination.JmsDestinationAccessor.resolveDestinationName(JmsDestinationAccessor.java:100)
    at org.springframework.jms.listener.AbstractPollingMessageListenerContainer.createListenerConsumer(AbstractPollingMessageListenerContainer.java:221)
    at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.initResourcesIfNecessary(DefaultMessageListenerContainer.java:1081)
    at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.invokeListener(DefaultMessageListenerContainer.java:1058)
    at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.executeOngoingLoop(DefaultMessageListenerContainer.java:1050)
    at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.run(DefaultMessageListenerContainer.java:947)
    at java.lang.Thread.run(Thread.java:662)

This log message is repeated again and again infinitely and for the other two workers also. And the build hangs at this point. I use unitils framework for integration testing and create spring context using @SpringApplicationContext in my base integration test class. Where am I going wrong?

EmeraldTablet
  • 812
  • 3
  • 12
  • 30

4 Answers4

3

This happened to me when I wanted to access the same durable subscription (i.e. topic) with the same client ID (ConnectionFactory.setClientId). Assigning unique client IDs to the clients solved the problem.

Gábor Paller
  • 175
  • 1
  • 8
1

Not sure this was the issue, but I solved my problem with this approach:

Using @SpringApplicationContext multiple spring xml files were being loaded and one of the spring xml file which loaded at last has excluded few classes required for the other context xmls and the context was reloaded excluding those classes.

I also saw few spring xmls were repeated in the context file list of @SpringApplicationContext

I removed the redundancies and reordered or removed the unwanted spring xmls or few beans in it. And it worked.

EmeraldTablet
  • 812
  • 3
  • 12
  • 30
0

You're trying to do a lookup of a JMS listener which is not present in the JNDI namespace. Are you sure you are running a JNDI container and your MQ server is running and set up correctly?

Kurt Du Bois
  • 7,550
  • 4
  • 25
  • 33
  • The same configuration is working for other modules in my application. When tests in this particular module is executed, it is throwing all these error messages. – EmeraldTablet Jan 29 '14 at 07:17
  • Yes Kurt, it is. As I said, it is working fine for other modules. The difference between other modules and this is, the integration tests here are reusing the contexts created by the base class. Whereas in the other modules, all integration tests are creating its own contexts. – EmeraldTablet Jan 29 '14 at 07:35
0

I faced a similar kind of issue, in my case, I was getting this error till there was no publisher to the topic. As soon as there was a publisher and the message started to get published on the topic, the JMS listener was actively listening and the error message was gone. I was able to reproduce this issue again if there is nothing in the topic and no publisher. JMS start throwing this error, which is very weird.

Vikky
  • 1,123
  • 14
  • 16
  • Hi @Vikky, I have same weird situation, did you solve it? If you did could you explain to me? – ahmetyavuzoruc Aug 23 '23 at 07:48
  • Yeah, as I explained my application was listening to this topic, and another team application was supposed to publish the message on this topic. Till the time other team application was not connected to publish the message, I was getting this error. As soon as the publishing application was connected, I was able to receive the messages, and the error was gone. – Vikky Aug 25 '23 at 14:20