Announcement Announcement Module
Collapse
No announcement yet.
How to consume the messages from different URL? I want to avoid repetition in applica Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to consume the messages from different URL? I want to avoid repetition in applica

    I am using this below configuration and it is working fine to consume message from one node.

    myproperties.properties

    Code:
    jms.brokerurl=tcp://jms1.my.com:61616
    applicationContext.xml
    Code:
        <bean id="connectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory" 
        p:brokerURL="${jms.brokerurl}?jms.redeliveryPolicy.maximumRedeliveries=5" /> 
     
        <bean id="myMsgListener" class="my.MessageListener" /> 
     
        <jms:listener-container 
                container-type="default" 
                connection-factory="connectionFactory" 
                acknowledge="client" 
                concurrency="10-50" 
                cache="consumer"> 
            <jms:listener destination="someQueue" ref="myMsgListener" method="onMessage" /> 
        </jms:listener-container>
    My requirement, messages are going to distribute among 'n' different node. For example n=4, If I do copy-paste the above 'connectionFactory','Listener' and 'listener-container' configuration '4' time with different brokerURL and 'id', it will work. But based on the environment (like development, testing and production), the value of 'n' is going to vary.
    So I can't keep changing my applicationContext.xml. We have script in place to expand the value in properties file as below with respect to environment. Part of deployment, this script will expand the values in property file.

    myproperties.properties
    Code:
    jms.brokerurl=tcp://jms1.my.com:61616,tcp://jms2.my.com:61616,tcp://jms3.my.com:61616,tcp://jms4.my.com:61616
    Based on the above ',' separated 'jms.brokerurl' property, I want to do this dynamic configuration in application context to consume the messages from the different nodes. Please share your ideas.
    Last edited by smaheskumar; Aug 12th, 2012, 12:26 AM.

  • #2
    If I understand your problem correctly then you can insert multiple listern on differnt topics/queue like this :

    <jms:listener-container
    container-type="default"
    connection-factory="connectionFactory"
    acknowledge="client"
    concurrency="10-50"
    cache="consumer">
    <jms:listener destination="someQueue" ref="myMsgListener" method="onMessage" />
    <jms:listener destination="otherQueue" ref="myMsgListener" method="onMessage" />
    </jms:listener-container>

    Comment


    • #3
      I think you didn't understand this problem. Let me put my current configuration(refer below). In this configuration, I have configured for 4 nodes/machine/host. Here I am repeating the configuration with different values and this number of node configuration is dynamic based on the environment. It mean, I have to consume it from 2 nodes in testing environment and I have to consume it from 4 nodes in production environment. The below listed configuration is working fine for production. But I have to comment number nodes if want to use it on testing environment.

      So, instead of this approach, i am looking for dynamic one. If you have any question, let me know.

      Code:
      <amq:connectionFactory id="wfReqAMQRecConFactory"
      		userName="${REC_MYREQ_MQ_USER}" password="${REC_MYREQ_MQ_PASSWORD}">
      	</amq:connectionFactory>
      	<bean id="myMsgHandler"
      		class="com.my.wfreqlistener.msgq.MyListenerMsgHandler" />
      	<!-- ******************************************************************* -->
      	<!-- ***					Node-1									 *** -->
      	<!-- ******************************************************************* -->
      	<bean id="myQueueListener1" class="com.my.common.msgq.MyQueueListener" >
      		<property name="messageHandler" ref="myMsgHandler" />
      	</bean>			
      	<bean id="myReceiverConFactory1" class="org.apache.activemq.ActiveMQConnectionFactory"
      		depends-on="myAMQRecConFactory">
      		<property name="brokerURL"
      			value="${REC_MYREQ_BROKER_URL1}?jms.redeliveryPolicy.maximumRedeliveries=${AMQ_MAX_RMyRY}&amp;jms.redeliveryPolicy.initialRedeliveryDelay=${AMQ_MAX_RMyRY_DELAY}&amp;jms.redeliveryPolicy.deliveryDelay=${AMQ_MAX_RMyRY_DELAY}&amp;jms.redeliveryPolicy.useExponentialBackOff=true&amp;jms.redeliveryPolicy.backOffMultiplier=2" />
      	</bean>
      	<jms:listener-container concurrency="${MYREQ_QUEUE_CONCURRENT_CONSUMERS}"
      		connection-factory="myReceiverConFactory1" acknowledge="transacted">
      		<jms:listener id="reqQueueListener1" destination="${MYREQ_QUEUE_NAME}" ref="myQueueListener1"/>
      	</jms:listener-container>
      	<!-- ******************************************************************* -->
      	<!-- ***					Node-2									 *** -->
      	<!-- ******************************************************************* -->
      	<bean id="myQueueListener2" class="com.my.common.msgq.MyQueueListener" >
      		<property name="messageHandler" ref="myMsgHandler" />
      	</bean>		
      	<bean id="myReceiverConFactory2" class="org.apache.activemq.ActiveMQConnectionFactory"
      		depends-on="myAMQRecConFactory">
      		<property name="brokerURL"
      			value="${REC_MYREQ_BROKER_URL2}?jms.redeliveryPolicy.maximumRedeliveries=${AMQ_MAX_RMyRY}&amp;jms.redeliveryPolicy.initialRedeliveryDelay=${AMQ_MAX_RMyRY_DELAY}&amp;jms.redeliveryPolicy.deliveryDelay=${AMQ_MAX_RMyRY_DELAY}&amp;jms.redeliveryPolicy.useExponentialBackOff=true&amp;jms.redeliveryPolicy.backOffMultiplier=2" />
      	</bean>
      	<jms:listener-container concurrency="${MYREQ_QUEUE_CONCURRENT_CONSUMERS}"
      		connection-factory="myReceiverConFactory2" acknowledge="transacted">
      		<jms:listener id="reqQueueListener2" destination="${MYREQ_QUEUE_NAME}" ref="myQueueListener2"/>
      	</jms:listener-container>	
      	<!-- ******************************************************************* -->
      	<!-- ***					Node-3									 *** -->
      	<!-- ******************************************************************* -->
      	<bean id="myQueueListener3" class="com.my.common.msgq.MyQueueListener" >
      		<property name="messageHandler" ref="myMsgHandler" />
      	</bean>			
      	<bean id="myReceiverConFactory3" class="org.apache.activemq.ActiveMQConnectionFactory"
      		depends-on="myAMQRecConFactory">
      		<property name="brokerURL"
      			value="${REC_MYREQ_BROKER_URL3}?jms.redeliveryPolicy.maximumRedeliveries=${AMQ_MAX_RMyRY}&amp;jms.redeliveryPolicy.initialRedeliveryDelay=${AMQ_MAX_RMyRY_DELAY}&amp;jms.redeliveryPolicy.deliveryDelay=${AMQ_MAX_RMyRY_DELAY}&amp;jms.redeliveryPolicy.useExponentialBackOff=true&amp;jms.redeliveryPolicy.backOffMultiplier=2" />
      	</bean>
      	<jms:listener-container concurrency="${MYREQ_QUEUE_CONCURRENT_CONSUMERS}"
      		connection-factory="myReceiverConFactory3" acknowledge="transacted">
      		<jms:listener id="reqQueueListener3" destination="${MYREQ_QUEUE_NAME}" ref="myQueueListener3"/>
      	</jms:listener-container>
      	<!-- ******************************************************************* -->
      	<!-- ***					Node-4									 *** -->
      	<!-- ******************************************************************* -->
      	<bean id="myQueueListener4" class="com.my.common.msgq.MyQueueListener" >
      		<property name="messageHandler" ref="myMsgHandler" />
      	</bean>			
      	<bean id="myReceiverConFactory4" class="org.apache.activemq.ActiveMQConnectionFactory"
      		depends-on="myAMQRecConFactory">
      		<property name="brokerURL"
      			value="${REC_MYREQ_BROKER_URL4}?jms.redeliveryPolicy.maximumRedeliveries=${AMQ_MAX_RMyRY}&amp;jms.redeliveryPolicy.initialRedeliveryDelay=${AMQ_MAX_RMyRY_DELAY}&amp;jms.redeliveryPolicy.deliveryDelay=${AMQ_MAX_RMyRY_DELAY}&amp;jms.redeliveryPolicy.useExponentialBackOff=true&amp;jms.redeliveryPolicy.backOffMultiplier=2" />
      	</bean>
      	<jms:listener-container concurrency="${MYREQ_QUEUE_CONCURRENT_CONSUMERS}"
      		connection-factory="myReceiverConFactory4" acknowledge="transacted">
      		<jms:listener id="reqQueueListener4" destination="${MYREQ_QUEUE_NAME}" ref="myQueueListener4"/>
      	</jms:listener-container>
      	<!-- ******************************************************************* -->

      Comment


      • #4
        See this thread on how to dynamically create parameterized context snippets.

        http://forum.springsource.org/showth...apter-creation

        Comment

        Working...
        X