Spring configuration for multiple Activemq remote brokers

kenn3th picture kenn3th · Nov 8, 2012 · Viewed 7.3k times · Source

How to configure multiple remote activemq brokers (different IP address) in spring context? Below is the configuration for 1 remote broker. I am using camel to create routes that produce and consume messages from and to different queues in multiple remote brokers. Based on the following routes, how do the system knows which remote broker each queue belongs to?

  • List item

    from("direct:start").to("activemq:queue:outgoingRequests")

  • List item

    from("activemq:queue:incomingOrders").to("log:Events? showAll=true").to("bean:jmsService")

Spring context for 1 broker org.camel.routes

<bean id="jmsConnectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory">
    <property name="brokerURL" value="tcp://10.1.11.97:61616" />
</bean>

<bean id="pooledConnectionFactory"
    class="org.apache.activemq.pool.PooledConnectionFactory" init-
            method="start" destroy-method="stop">
    <property name="maxConnections" value="8" />
    <property name="connectionFactory" ref="jmsConnectionFactory" />
</bean>

<bean id="jmsConfig" class="org.apache.camel.component.jms.JmsConfiguration">
    <property name="connectionFactory" ref="pooledConnectionFactory"/>
    <property name="concurrentConsumers" value="10"/>
</bean>

<bean id="activemq" class="org.apache.activemq.camel.component.ActiveMQComponent">
    <property name="configuration" ref="jmsConfig"/>
</bean>

Answer

Petter Nordlander picture Petter Nordlander · Nov 8, 2012

Just add more components with different names

<bean id="activemq" class="org.apache.activemq.camel.component.ActiveMQComponent">
   <property name="configuration" ref="jmsConfig"/>
</bean>

<bean id="activemq2" class="org.apache.activemq.camel.component.ActiveMQComponent">
   <property name="configuration" ref="myOtherJmsConfig"/>
</bean>

Then simply use the names:

<from uri="activemq:queue:MY.QUEUE"/><!-- get from "1st" ActiveMQ -->
<to uri="activemq2:queue:MY.QUEUE"/> <!-- put to same queue name on other ActiveMQ -->

Actually, you can call them whatever you want, like "EuropeanMarketBroker" or whatever fits in.