Results 1 to 3 of 3

Thread: Configuring a Topic with ActiveMQ

  1. #1
    Join Date
    Oct 2011
    Location
    Montreal, CA
    Posts
    2

    Default Configuring a Topic with ActiveMQ

    I know it is supposed to be easy, but all samples for creating topics with Spring are failing for me. As an example, my latest context below. The producer (I changed it so much, so do not bother that the producer has also an ID "xyz_listener") is sending message to the proper jms.productT topic, but my listener is always registering for a queue named productT.

    For routing the message I also cheked on debug my JndiDestinationResolver working fine with Topic.class. So why should Spring register a listener on DefaultMessageListenerContainer pointing to a Queue.class?

    Can anyone see my config mistake?

    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.springframework.org/schema/p"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:jms="http://www.springframework.org/schema/jms" xmlns:amq="http://activemq.apache.org/schema/core"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schem...ring-beans.xsd
    http://www.springframework.org/schema/context
    http://www.springframework.org/schem...ng-context.xsd
    http://www.springframework.org/schema/jms
    http://www.springframework.org/schem...spring-jms.xsd
    http://activemq.apache.org/schema/core
    http://activemq.apache.org/schema/core/activemq-core.xsd">

    <bean id="jndiTemplate" class="org.springframework.jndi.JndiTemplate">
    <property name="environment">
    <props>
    <prop key="java.naming.factory.initial">
    org.apache.activemq.jndi.ActiveMQInitialContextFac tory
    </prop>
    <prop key="connection.TopicAC.brokerURL">tcp://localhost:61616</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>
    <prop key="connectionFactoryNames">TopicAC</prop>

    <prop key="topic.productT">jms.productT</prop>
    </props>
    </property>
    </bean>

    <bean id="jndiTopicConnectionFactory" class="org.springframework.jndi.JndiObjectFactoryB ean">
    <property name="jndiTemplate" ref="jndiTemplate" />
    <property name="jndiName" value="TopicAC" />
    </bean>

    <bean id="topicConnectionFactory"
    class="org.springframework.jms.connection.CachingC onnectionFactory">
    <property name="targetConnectionFactory" ref="jndiTopicConnectionFactory" />
    <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" />
    <property name="fallbackToDynamicDestination" value="false" />
    </bean>

    <!-- <bean id="productT" class="org.apache.activemq.command.ActiveMQTopic"> -->
    <!-- <constructor-arg value="jms.productT" /> -->
    <!-- </bean> -->

    <bean id="jmsTopicTemplate" class="org.springframework.jms.core.JmsTemplate">
    <property name="connectionFactory" ref="topicConnectionFactory" />
    <property name="destinationResolver" ref="destinationResolver" />
    <property name="pubSubDomain" value="true" />
    </bean>

    <bean id="productListener" class="com.ypg.jms.server.ProductProcessor">
    <property name="connectionFactory" ref="topicConnectionFactory" />
    <property name="messageT" ref="jmsTopicTemplate" />
    <property name="topicName" value="productT" />
    </bean>


    <bean id="websiteListener" class="com.ypg.jms.server.WebsiteListener" />
    <bean id="campaignListener" class="com.ypg.jms.server.CampaignListener" />

    <bean id="jmsContainer"
    class="org.springframework.jms.listener.DefaultMes sageListenerContainer">
    <property name="connectionFactory" ref="topicConnectionFactory" />
    <!-- <property name="destinationName" ref="productT" /> -->
    <property name="destinationName" value="productT" />
    <property name="messageListener" ref="websiteListener" />
    </bean>
    </beans>

  2. #2
    Join Date
    Oct 2005
    Location
    Boston, MA
    Posts
    2,840

    Default

    You need to specify the "pubSubDomain" property on the MessageListener container instance (with a value of TRUE). That way when it uses the DestinationResolver, it knows to consider Topics instead of Queues.

  3. #3
    Join Date
    Oct 2011
    Location
    Montreal, CA
    Posts
    2

    Default

    Hi Mark, thanks for the answer.

    So I got it all wrong, right? I thought I should have to put it on my JmsTemplate (to be injected on the Producer). When actually, it should be set on my Container. Now I got my example working just fine.



    <bean id="jmsContainer"
    class="org.springframework.jms.listener.DefaultMes sageListenerContainer">
    <property name="connectionFactory" ref="topicConnectionFactory" />
    <!-- <property name="destinationName" ref="productT" /> -->
    <property name="destinationName" value="productT" />
    <property name="pubSubDomain" value="true" />
    <property name="messageListener" ref="websiteListener" />
    </bean>

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •