简体   繁体   English

Spring侦听器未捕获JMS消息

[英]JMS message not picked up by Spring listener

I have a Spring app running inside a standalone JBoss EAP 6.2 (with its embedded HornetQ provider). 我有一个在独立的JBoss EAP 6.2(带有嵌入式HornetQ提供程序)内运行的Spring应用程序。

Messages are succcesfully put on the queue (I can see them in jboss-eap-6.2\\standalone\\data\\messagingjournal\\hornetq-data-1.hq because the queue is durable), but not picked up by the listener (a breakpoint inside the listener is not hit). 消息被巧妙地放在队列中(我可以在jboss-eap-6.2 \\ standalone \\ data \\ messagingjournal \\ hornetq-data-1.hq中看到它们,因为队列是持久的),但是没有被侦听器拾取(内部断点)听众没有被击中)。 I suspect something is missing from or wrong in the configuration but cannot see what. 我怀疑配置中缺少或错误但看不清楚是什么。 JBoss starts without any validation errors. JBoss启动时没有任何验证错误。

First, the excerpt from Spring's applicationContext.xml: 首先,摘自Spring的applicationContext.xml:

The JNDI names of the connection factory and queue match those in JBoss' standalone-full.xml 连接工厂和队列的JNDI名称与JBoss的standalone-full.xml中的名称相匹配

<jee:jndi-lookup id="jmsConnectionFactory" jndi-name="java:/JmsXA" resource-ref="false" proxy-interface="javax.jms.ConnectionFactory"/> 

<jee:jndi-lookup id="myQueue" jndi-name="java:jboss/exported/jms/queue/myQueue"/> 

<bean id="myHandler" class="com.example.MyHandler" />

<jms:listener-container destination-type="queue" acknowledge="auto" connection-factory="jmsConnectionFactory">
    <jms:listener destination="java:jboss/exported/jms/queue/myQueue" ref="myHandler" method="processMessage" />
</jms:listener-container>

The message handler is declared as a Spring component and the class and method names match what is declared above: 消息处理程序声明为Spring组件,类和方法名称与上面声明的名称匹配:

@Component
public class MyHandler {

public void processMessage(MyMessage delaySendTransfer) {
    //...
}

By default, Spring use the DynamicDestinationResolver for the listener container so it expects to receive a bean reference in the destination attribute of the listener. 默认情况下,Spring使用DynamicDestinationResolver作为侦听器容器,因此它希望在侦听器的destination属性中接收bean引用。 Since you are using a JNDI name, you should set the destination resolver strategy to jndiDestinationResolver . 由于您使用的是JNDI名称,因此应将目标解析器策略设置为jndiDestinationResolver

<jms:listener-container destination-resolver="jndiDestinationResolver" destination-type="queue" acknowledge="auto" connection-factory="jmsConnectionFactory">
    <jms:listener destination="java:jboss/exported/jms/queue/myQueue" ref="myHandler" method="processMessage" />
</jms:listener-container>

Replacing the destination attribute value with the bean reference should also do the trick : 用bean引用替换目标属性值也应该可以解决问题:

<jms:listener-container destination-type="queue" acknowledge="auto" connection-factory="jmsConnectionFactory">
    <jms:listener destination="myQueue" ref="myHandler" method="processMessage" />
</jms:listener-container>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM