[英]Strange error in JMS Topic setup using Spring
I am getting a JMS listener failure error messages when starting JBoss. 启动JBoss时出现JMS侦听器失败错误消息。 I am using Spring to setup a topic with two subscribers.
我正在使用Spring来设置两个订阅者的主题。 Here is my setup:
这是我的设置:
<bean id="offerListner"
class="org.springframework.jms.listener.adapter.MessageListenerAdapter">
<constructor-arg>
<bean class="com.me.OfferListener" />
</constructor-arg>
</bean>
<bean id="orderListener"
class="org.springframework.jms.listener.adapter.MessageListenerAdapter">
<constructor-arg>
<bean class="com.me.OrderListener" />
</constructor-arg>
</bean>
<jms:listener-container connection-factory="connectionFactory" acknowledge="transacted" cache="connection" client-id="1" destination-type="durableTopic" >
<jms:listener destination="eventTopic" ref="offerListener" />
<jms:listener destination="eventTopic" ref="orderListener" />
</jms:listener-container>
When restarting JBoss I get a pattern of error message suggesting JBoss is struggling to initialize the JMS listener for my topic> This is the message I get: 重新启动JBoss时,我收到一条错误消息,提示JBoss正在努力为我的主题初始化JMS侦听器>这是我得到的消息:
2014-10-20 07:20:33,747 INFO [STDOUT] (A2-2) 07:20:33,747 WARN DefaultMessageListenerContainer:842 - Setup of JMS message listener invoker failed for destination 'eventTopic' - trying to recover. Cause: Cannot create a subscriber on the durable subscription since it already has subscriber(s)
2014-10-20 07:20:33,747 INFO [STDOUT] (A2-2) 07:20:33,747 INFO DefaultMessageListenerContainer:891 - Successfully refreshed JMS Connection
2014-10-20 07:20:38,754 INFO [STDOUT] (A2-3) 07:20:38,754 WARN DefaultMessageListenerContainer:842 - Setup of JMS message listener invoker failed for destination 'eventTopic' - trying to recover. Cause: Cannot create a subscriber on the durable subscription since it already has subscriber(s)
... and the message goes forever every 5 seconds. ...,并且消息每5秒钟永远发送一次。
My OrderListener and OfferListener both extend the same super class: 我的OrderListener和OfferListener都扩展了相同的超类:
public class OfferListener extends AbstractListener {...}
public class OrderListener extends AbstractListener {...}
This is a simple representation of the classes: 这是类的简单表示:
public abstract class AbstractListener<T> {
abstract protected void handleMessage(T message);
@RunAsAdmin
public void onMessage(Message message) {
// pre-process the message,
handleMessage( processedMessage );
}
}
There seem to be a problem in the AbstractListener method names. AbstractListener方法名称似乎有问题。 The Workaround Solution
解决方法
I can the problem if I define a unique marker interface for each listener, this for soem how uniquly identify each each listener, like this: 如果我为每个侦听器定义一个唯一的标记接口,就可以解决这个问题,因为这样做可以唯一地标识每个侦听器,如下所示:
public class OfferListener extends AbstractListener implements OfferListenerMarker {...}
public class OrderListener extends AbstractListener implements OrderListenerMarker {...}
Both OfferListenerMarker
and OrderListenerMarker
are empty interfaces. OfferListenerMarker
和OrderListenerMarker
都是空接口。 This technique solves my problem but it's ugly and I don't understand why. 这项技术解决了我的问题,但是很丑,我不明白为什么。 The issue seems to be related to JMS topic listeners having to have a unique identity.
这个问题似乎与必须具有唯一标识的JMS主题侦听器有关。 I thought the class itself (OrderListener and OfferListener) is a unique identity even if both extend the same abstract class.
我认为类本身(OrderListener和OfferListener)是唯一的标识,即使它们都扩展了相同的抽象类。
I am trying to find away to get rid of the marker interface, there mus be something in the topic setup that I could do to? 我试图摆脱标记界面,在主题设置中有什么我可以做的?
Thanks for reading this thread. 感谢您阅读此线程。
Try providing a unique subscription name 尝试提供唯一的订阅名称
<jms:listener-container connection-factory="connectionFactory" acknowledge="transacted" cache="connection" client-id="1" destination-type="durableTopic" >
<jms:listener destination="eventTopic" ref="offerListener" subscription="xyz" />
<jms:listener destination="eventTopic" ref="orderListener" subscription="abc" />
</jms:listener-container>
Basically to track durable subscriptions the JMS provider needs to be able to distinguish between two subscription. 基本上,为了跟踪持久订阅,JMS提供者需要能够区分两个订阅。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.