0
votes

I have been trying for couple days to set up multiple ActiveMQ connections in Spring Integration using XML configuration.

I am using spring boot, SI looks for a bean called jmsConnectionFactory in the context and uses it. But what if I have to send/listen to jms messages from/to different ActiveMQ servers?

What I have right now is this:

<bean id="jmsConnectionFactory1"
    class="org.springframework.jms.connection.CachingConnectionFactory">
    <property name="targetConnectionFactory">
        <bean class="org.apache.activemq.ActiveMQConnectionFactory">
            <property name="brokerURL" value="tcp://localhost:61616" />
        </bean>
    </property>
    <property name="sessionCacheSize" value="10" />
    <property name="cacheConsumers" value="false" />
</bean>

<bean id="jmsConnectionFactory2"
    class="org.springframework.jms.connection.CachingConnectionFactory">
    <property name="targetConnectionFactory">
        <bean class="org.apache.activemq.ActiveMQConnectionFactory">
            <property name="brokerURL" value="tcp://192.168.1.59:61616" />
        </bean>
    </property>
    <property name="sessionCacheSize" value="10" />
    <property name="cacheConsumers" value="false" />
</bean>
...
<jms:message-driven-channel-adapter channel="jmsInChannel" destination-name="queue.demo" />
<int:channel id="jmsInChannel" />
...

When trying to start the spring boot app I get this error:

***************************
APPLICATION FAILED TO START
***************************

Description:

A component required a bean named 'jmsConnectionFactory' that could not be found.

The following candidates were found but could not be injected:
- Bean method 'jmsConnectionFactory' in 'ActiveMQXAConnectionFactoryConfiguration' not loaded because @ConditionalOnClass did not find required class 'javax.transaction.TransactionManager'


Action:

Consider revisiting the entries above or defining a bean named 'jmsConnectionFactory' in your configuration.

I came across this solution, https://stackoverflow.com/a/43401330/3367392 it's a java configuration. Also I looked into this but it's using camel https://stackoverflow.com/a/13288312/3367392

Is there a way to achieve the same for Spring Integration using XML configuration?

1

1 Answers

1
votes

Ok so I got it, for a simple case I just had to add the right connectionFactory to the adapters like this

<jms:message-driven-channel-adapter channel="jmsInChannel"
    destination-name="queue.demo"
    connection-factory="jmsConnectionFactory1" />