Using ActiveMQ with Camel

Using Spring-DM

It is often easy to define two application contexts for spring-dm, it helps you re-use configuration in Junit tests
and cleanly separates OSGi from the normal spring application contexts.

You define these files in a bundle by adding them to the classpath under META-INF/spring

OSGi Application context

<?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:tx="http://www.springframework.org/schema/tx"
  xmlns:ctx="http://www.springframework.org/schema/context"
  xmlns:osgi="http://www.springframework.org/schema/osgi"
  xmlns:osgix="http://www.springframework.org/schema/osgi-compendium"
  xsi:schemaLocation="
    http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
    http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
    http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
    http://www.springframework.org/schema/osgi http://www.springframework.org/schema/osgi/spring-osgi.xsd
    http://www.springframework.org/schema/osgi-compendium http://www.springframework.org/schema/osgi-compendium/spring-osgi-compendium.xsd">

    <!-- Make sure we use the ServiceMix provided connection pool in our beans -->
    <osgi:reference id="jmsConnectionPool" interface="javax.jms.ConnectionFactory"/>

</beans>

Normal spring application context.

<?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:camel="http://camel.apache.org/schema/spring"
       xsi:schemaLocation="
        http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
        http://camel.apache.org/schema/spring
        http://camel.apache.org/schema/spring/camel-spring-${camel-version}.xsd">

    <camelContext xmlns="http://camel.apache.org/schema/spring">
        <route>
            <from uri="jms:queue:start"/>
            <to uri="mock:result"/>
        </route>
    </camelContext>

    <!-- This bean will import use the OSGi service from the context above -->
    <bean id="jms" class="org.apache.camel.component.jms.JmsComponent">
        <property name="connectionFactory" ref="jmsConnectionPool" />
        <!-- If you have a transaction manager configured
        <property name="transacted" value="true" />
        <property name="transactionManager" ref="transactionManager" />
        -->
    </bean>

</beans>