微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Spring JMS接收主题消息

我正在编写一个简单的教程.我有一个发布者,它发送关于主题的消息和订阅者以接收它.当我启动应用程序时,Spring配置文件加载,然后我收到以下错误

    2011-10-20 21:50:39,340 DEBUG [org.springframework.jms.support.destination.JndiDestinationResolver] - Located object with JNDI name [Ratetopic]
2011-10-20 21:50:39,340 DEBUG [org.springframework.jms.connection.CachingConnectionFactory] - Closing cached Session: ActiveMQSession {id=ID:Reverb0253-PC-62259-1319161839013-0:1:3,started=true}
2011-10-20 21:50:39,340 DEBUG [org.springframework.jms.connection.CachingConnectionFactory] - Closing cached Session: ActiveMQSession {id=ID:Reverb0253-PC-62259-1319161839013-0:1:2,started=true}
2011-10-20 21:50:44,348 WARN [org.springframework.jms.listener.DefaultMessageListenerContainer] - Setup of JMS message listener invoker Failed for destination 'Ratetopic' - trying to recover. Cause: Destination [Ratetopic] is not of expected type [javax.jms.Queue]
org.springframework.jms.support.destination.DestinationResolutionException: Destination [Ratetopic] is not of expected type [javax.jms.Queue]
    at org.springframework.jms.support.destination.JndiDestinationResolver.validateDestination(JndiDestinationResolver.java:147)
    at org.springframework.jms.support.destination.JndiDestinationResolver.resolveDestinationName(JndiDestinationResolver.java:112)
    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:1057)
    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:722)

为什么春天认为它应该是一个队列而不是主题

我的jndi文件看起来像这样

java.naming.factory.initial = org.apache.activemq.jndi.ActiveMQInitialContextFactory
java.naming.provider.url = tcp://localhost:61616
java.naming.security.principal=system
java.naming.security.credentials=manager
connectionFactoryNames = TopicCF
topic.Ratetopic = Ratetopic

spring配置文件

ecurity.principal">systemecurity.credentials">managerdiobjectfactorybean">
    etopic"/>
    NowledgeModeName" value="AUTO_ACKNowLEDGE"/>

我的订阅者实现了MessageListener

@Override
public void onMessage(Message message) {
    try {
        // Get the data from the message
        BytesMessage msg = (BytesMessage) message;
        double newRate = msg.readDouble();
        // If the rate is at least 1 point lower than the current rate,then
        //recommend refinancing
        if ((currentRate - newRate) >= 1.0) {
            System.out.println(
                    "New rate = " + newRate + " - Consider refinancing loan");
        } else {
            System.out.println("New rate = " + newRate + " - Keep existing loan");
        }
        System.out.println("\nWaiting for rate updates...");
    } catch (Exception ex) {
        ex.printstacktrace(System.out);
        System.exit(1);
    }
}

public static void main(String argv[]) {

    ApplicationContext ctx = new ClasspathXmlApplicationContext("app-context.xml");

    try {
        // Run until enter is pressed
        BufferedReader stdin = new BufferedReader(new InputStreamReader(system.in));
        System.out.println("TBorrower application started");
        System.out.println("Press enter to quit application");
        stdin.readLine();
    } catch (IOException ioe) {
        ioe.printstacktrace();
    }
}
最佳答案
您尝试使用某个主题,但是您没有在DefaultMessageListenerContainer上设置pubSubDomain属性,它认为“false”,这意味着点对点,这意味着队列而不是主题.因此,错误消息告诉您Ratetopic不是javax.jms.Queue.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐