Hi,

In Camel, the CamelContext in not accessed from within a RouteBuilder.

A bit of background: using the DSL the RouteBuilder builds up a set of definition objects (POJOs) that define how the routing within a route. This is then interpreted by the CamelContext, which creates a second set of objects that are the implementation classes of the route which will process the Exchanges flowing down it. So the CamelContext calls the RouteBuilder, and not the other way around.

The CamelContext has a Registry that maps to the Spring context. Any bean defined in the Spring context is accessible by name.

So you would do something like:

<beans>
<bean id="activemq" class="org.apache.activemq.camel.ActiveMQComponent">
        <property name="brokerURL" "failover:(tcp://someBox:61616)"/>
    </bean>

    <bean id="myRoute" class="...JettyRouteBuilder"/>

    <camelContext>
        <routeBuilder ref="myRoute"/>
    </camelContext>
</beans>

Hope that helps,

Jakub

On 22/07/15 16:02, kdnigh wrote:
Hi everyone,

I'm trying to send a jms message to a remote activemq broker on a remote
servicemix instance. I believe I would first need to create an
ActiveMQConnectionFactory object and add that to the default camelContext.
If this is correct, how do I access the default camelContext (which is just
a spring bean), from my routebuilder class? I was thinking something like:

@Component
public class JettyRouteBuilder extends SpringRouteBuilder {

     @Override
     public void configure() {
        camelContext.addComponent("activemq",
activeMQComponent("tcp://10.1.2.3:61616"));
        from("jetty:http://0.0.0.0:8888/mytestservice";).to("activemq");
        ...

I'm not sure about the syntax in the .to(...) method or how i extract
camelContext from serviceMix since I've defined it in:

<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.0.xsd
        http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
        http://camel.apache.org/schema/spring
http://camel.apache.org/schema/spring/camel-spring.xsd";>


     <camel:camelContext id="camel5">
         <packageScan>
             <package>org.apache.servicemix.examples.camel</package>
         </packageScan>
     </camel:camelContext>

</beans>

Thanks in advance for any help!



--
View this message in context: 
http://servicemix.396122.n5.nabble.com/How-to-create-a-camel-route-to-remote-ActiveMQ-broker-tp5722843.html
Sent from the ServiceMix - Dev mailing list archive at Nabble.com.

Reply via email to