JMS消息侦听器调用程序的设置因尝试恢复的目标而失败

时间:2014-01-29 06:26:15

标签: spring spring-jms

在我的应用程序中运行集成测试时,我在以下集成测试之一的故障安全测试报告中收到以下错误消息:

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

以下是我的配置详细信息:

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

集成测试有一个基类,用于创建spring应用程序上下文,并由模块中的所有其他集成测试共享。
我启用了调试级别的日志记录,并收到以下错误消息:

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)

此日志消息会一次又一次地无限重复,另外两名工作人员也会重复。而构建在这一点上依然存在。我使用unitils框架进行集成测试,并在我的基本集成测试类中使用@SpringApplicationContext创建spring上下文。我哪里错了?

3 个答案:

答案 0 :(得分:1)

不确定这是问题,但我用这种方法解决了我的问题:

正在加载@SpringApplicationContext多个spring xml文件,并且最后加载的一个spring xml文件排除了其他上下文xmls所需的几个类,并且重新加载了上下文,不包括这些类。

我还看到在@SpringApplicationContext

的上下文文件列表中重复了几个spring xmls

我删除了裁员并重新排序或删除了不需要的弹簧xmls或其中的几个bean。它起作用了。

答案 1 :(得分:0)

您正在尝试查找JNDI名称空间中不存在的JMS侦听器。您确定要运行JNDI容器并且MQ服务器正在运行并正确设置吗?

答案 2 :(得分:0)

当我想访问具有相同客户端ID(ConnectionFactory.setClientId)的相同持久订阅(即主题)时,这发生在我身上。为客户端分配唯一的客户端ID解决了这个问题。