On 4/29/07, dr.jeff <[EMAIL PROTECTED]> wrote:
I have tried and completely failed to use the camel spring container.

I see where it can do two things:

1) create a context which instantiates RouteBuilders in a given package:
  <bean id="camel" class="org.apache.camel.spring.CamelContextFactoryBean">
    <property name="packages" value="org.apache.camel.spring.example"/>
  </bean>
I can't even guess what the need for that is, unless it's just a shortcut
for declaring those RouteBuilders in the xml.

Bingo! :)


2) create RouteBuilders in xml:
    <routeBuilder id="buildSimpleRoute"
xmlns="http://activemq.apache.org/camel/schema/camel-1.0.xsd";>
       <route>
         <from uri="queue:a"/>
         <to uri="queue:b"/>
       </route>
    </routeBuilder>
That seems more useful, since I can get the routes and add them to a
CamelContext, like this:
        container = new DefaultCamelContext();
        //or: container = SpringCamelContext.springCamelContext(ctx);
        Map<String, RouteBuilder> map = ctx.getBeansOfType(RouteBuilder.class);
        Iterator<RouteBuilder> iter = map.values().iterator();
        List<Route> routes = new ArrayList<Route>();
        while(iter.hasNext()) {
                RouteBuilder builder = iter.next();
                try {
                        routes.addAll(builder.getRouteList());
                } catch (Exception e) {
                        log.error(e);
                }
        }
        container.addRoutes(routes);
        container.start();

The problem is, the routes don't work.

Doing this by hand, you need to make sure you inject the context into
the RouteBuilder.

You could instead do...

container.addRoutes(builder);

which will probably fix your issue.


Note that if you are using a spring.xml file you can just use the
CamelContextFactoryBean directly then when you look up your
CamelContext it will have all the routes configured...
https://svn.apache.org/repos/asf/activemq/camel/trunk/camel-spring/src/test/resources/org/apache/camel/spring/routingUsingCamelContextFactoryTest.xml

there's a test case that shows this working...
https://svn.apache.org/repos/asf/activemq/camel/trunk/camel-spring/src/test/java/org/apache/camel/spring/RoutingUsingCamelContextFactoryTest.java


--
James
-------
http://macstrac.blogspot.com/

Reply via email to