简体   繁体   English

您如何使用 Spring JMS 收听 JMS 主题

[英]How do you listen to a JMS topic using Spring JMS

I have a HornetQ server which has topic and queue's.我有一个带有主题和队列的 HornetQ 服务器。 I am not aware of the config on the other side but the way I connect to the Queue is:我不知道另一端的配置,但我连接到队列的方式是:

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

<bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate">
    <property name="connectionFactory" ref="connectionFactory"/>
    <property name="defaultDestination" ref="destination"/>
    <property name="pubSubDomain" value="false"/>
    <property name="deliveryPersistent" value="true"/>
    <property name="deliveryMode" value="2"/>
</bean>

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

<!-- Listener Asynchronous -->
<bean id="queueListener" class="com.my.queueListener"/>

<jms:listener-container concurrency="5-10">
             <jms:listener destination="QUEUE_NAME" ref="queueListener"/>
</jms:listener-container>

I had set the pubSubDomain to true and it worked (strange but true).我已将pubSubDomain设置为true并且它起作用了(奇怪但正确)。 Anyhow now I want to connect to a topic.无论如何,现在我想连接到一个主题。 I set the pubSubDomain as true and still it gives me an error saying我将pubSubDomain设置为true但它仍然给我一个错误说

WARNING: Setup of JMS message listener invoker failed for destination 'Activate_NTD' - trying to recover.警告:目标“Activate_NTD”的 JMS 消息侦听器调用程序设置失败 - 尝试恢复。 Cause: There is no queue with name TOPIC_NAME原因:没有名为 TOPIC_NAME 的队列

I know HornetQ behaves a bit differently as specified here:我知道 HornetQ 的行为与此处指定的有所不同:

exact example for JMS Topic in HornetQ HornetQ 中 JMS 主题的确切示例

but I am unable to figure out what to do and how to get this working.但我无法弄清楚该怎么做以及如何让它发挥作用。

Set the destination-type on the container that defaults to queue, something like在默认为队列的容器上设置destination-type ,例如

<jms:listener-container destination-type="topic" concurrency="5-10">
         <jms:listener destination="TOPIC_NAME" ref="topicListener"/>
</jms:listener-container>

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

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