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

Почему Spring думает, что это должна быть очередь, а не тема

, мой файл 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 - это

<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">tcp://localhost:61616</prop>
            <prop key="java.naming.security.principal">system</prop>
            <prop key="java.naming.security.credentials">manager</prop>
        </props>
    </property>
</bean>

<bean id="jndiTopicConnFactory" class="org.springframework.jndi.JndiObjectFactoryBean">
    <property name="jndiTemplate" ref="jndiTemplate"/>
    <!-- JNDI name of connection factory as defined by provider -->
    <property name="jndiName" value="TopicCF"/>
</bean>

<bean id="topicConnFactory" class="org.springframework.jms.connection.CachingConnectionFactory">
    <property name="targetConnectionFactory" ref="jndiTopicConnFactory"/>
    <!-- Number of sessions that will be cached -->
    <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"/>
    <!-- do not create a dynamic destination if the destination name is not found in JNDI -->
    <property name="fallbackToDynamicDestination" value="false"/>
</bean>

<bean id="messageListener" class="com.merc.springjmspubsublenderborrower.TBorrower"/>

<bean id="jmsContainer" class="org.springframework.jms.listener.DefaultMessageListenerContainer">
    <property name="connectionFactory" ref="topicConnFactory"/>
    <property name="destinationResolver" ref="destinationResolver"/>
    <property name="concurrentConsumers" value="3" />
    <property name="destinationName" value="RateTopic"/>
    <property name="messageListener" ref="messageListener" />
    <property name="sessionAcknowledgeModeName" value="AUTO_ACKNOWLEDGE"/>
</bean>

Мой подписчик реализует 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();
    }
}
5
задан Maciej Walkowiak 2 December 2014 в 00:20
поделиться