Announcement Announcement Module
Collapse
No announcement yet.
Topic consumers setup in AMQ+Spring Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Topic consumers setup in AMQ+Spring

    Hi !

    I am new to AMQ+SPRING and struggling to get it working.

    I have scenario as below:
    1. Successfully setup AMQ 5.3 server running on tcp
    Defined Queue and Topics in activemq.xml, AMQ admin shows them correctly

    2. In my swing client application,
    on some action, class1 creates message and puts in Queue in AMQ so that only single listeners gets message.
    on some action, class2 creates message and puts in Topic in AMQ so that multiple listeners get same message.

    3. In swing client application, I have created spring-config.xml as follows:

    Code:
    <!-- enables annotation based configuration -->
    <context:annotation-config />
    
    <!-- scans for annotated classes in the com.company package -->
    <context:component-scan base-package="com.company.jms"/>
    
    <!-- allows for ${} replacement in the spring xml configuration from the system.properties file on the classpath -->
    <context:property-placeholder location="classpath:system.properties"/>
    
    <!-- creates an activemq connection factory using the amq namespace -->
    <amq:connectionFactory id="connectionFactory" brokerURL="${jms.brokerURL}" />
    
    <bean id="singleConnectionFactory" class="org.springframework.jms.connection.SingleConnectionFactory">
    	<property name="targetConnectionFactory" ref="connectionFactory"/>
    	<property name="reconnectOnException" value="true"/>
    </bean>
    
    <bean id="cachingConnectionFactory" class="org.springframework.jms.connection.CachingConnectionFactory">
    	<property name="targetConnectionFactory" ref="singleConnectionFactory"/>
    	<property name="exceptionListener" ref="jmsExceptionListener"/>
    	<property name="sessionCacheSize" value="100"/>
    </bean>
    
    <!-- Queues/Topics -->
    <bean id="myQueue1" class="org.apache.activemq.command.ActiveMQQueue">
       <constructor-arg value="myQueue1"/>
    </bean>
    <bean id="myQueue2" class="org.apache.activemq.command.ActiveMQQueue">
       <constructor-arg value="myQueue2"/>
    </bean>
    <bean id="myTopic1" class="org.apache.activemq.command.ActiveMQTopic">
       <constructor-arg value="myTopic1"/>
    </bean>
    <bean id="myTopic2" class="org.apache.activemq.command.ActiveMQTopic">
       <constructor-arg value="myTopic2"/>
    </bean>
    
    <!-- JmsTemplates -->
    <bean id="jmsTemplateQueue1" class="org.springframework.jms.core.JmsTemplate">
    	<property name="connectionFactory" ref="cachingConnectionFactory"/>
    	<property name="defaultDestination" ref="myQueue1"/>
    	<property name="explicitQosEnabled" value="true"/>
    	<property name="timeToLive" value="${jms.myQueue1.timetolive}"/>
    </bean>
    <bean id="jmsTemplateQueue2" class="org.springframework.jms.core.JmsTemplate">
    	<property name="connectionFactory" ref="cachingConnectionFactory"/>
    	<property name="defaultDestination" ref="myQueue2"/>
    	<property name="explicitQosEnabled" value="true"/>
    	<property name="timeToLive" value="${jms.myQueue2.timetolive}"/>
    </bean>
    <bean id="jmsTemplateTopic1" class="org.springframework.jms.core.JmsTemplate">
    	<property name="connectionFactory" ref="cachingConnectionFactory"/>
    	<property name="defaultDestination" ref="myTopic1"/>
    	<property name="pubSubDomain" value="true"/>
    	<property name="explicitQosEnabled" value="true"/>
    	<property name="timeToLive" value="${jms.myTopic1.timetolive}"/>
    </bean>
    <bean id="jmsTemplateTopic2" class="org.springframework.jms.core.JmsTemplate">
    	<property name="connectionFactory" ref="cachingConnectionFactory"/>
    	<property name="defaultDestination" ref="myTopic2"/>
    	<property name="pubSubDomain" value="true"/>
    	<property name="explicitQosEnabled" value="true"/>
    	<property name="timeToLive" value="${jms.myTopic2.timetolive}"/>
    </bean>
    
    <jms:listener-container connection-factory="singleConnectionFactory">
        <jms:listener id="Queue1Listener" destination="myQueue1" ref="Queue1Listener" />
        <jms:listener id="Queue2Listener" destination="myQueue2" ref="Queue2Listener" />
        <jms:listener id="Topic1Listener1" destination="myTopic1" ref="Topic1Listener1" />
        <jms:listener id="Topic1Listener2" destination="myTopic1" ref="Topic1Listener2" />
        <jms:listener id="Topic2Listener1" destination="myTopic2" ref="Topic1Listener1" />
        <jms:listener id="Topic2Listener2" destination="myTopic2" ref="Topic2Listener2" />
    </jms:listener-container>
    </beans>
    I am not sure if I have bind multiple consumers to Topic rightly.
    Also noticed that AMQ admin shows myTopic1 and myTopic2 under "Queues" after running my app !
    Your kind guidence will get me going.

    Thank you very much.
    Nitin

  • #2
    As far as I know Spring-AMQP is currently only supporting RabbitMQ implementation.

    Someone from Spring correct me if I'm wrong.

    Comment

    Working...
    X