On 4/30/07, James Strachan <[EMAIL PROTECTED]> wrote:
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
BTW here's an example using the spring 2 namespaces approach to
configuring a CamelContext along with some routes
https://svn.apache.org/repos/asf/activemq/camel/trunk/camel-spring/src/test/resources/org/apache/camel/spring/routingUsingCamelContextFactoryWithNamespacesTest.xml
--
James
-------
http://macstrac.blogspot.com/