Hi

See chapter 13 in Camel in Action which covers how to dynamic at
runtime to start/stop etc routes.

CamelContext have both a start and stop route methods you can use.


On Thu, Apr 8, 2010 at 9:41 AM, CyrilForce <lum_...@hotmail.com> wrote:
>
> Hi All,
>
> I would like to know is there is any ways to start or fire the routes in
> java code. As i would have a applicationContent.xml for spring webapps which
> loads the camelContext with the route (disabled for autostartup).
>
> Code as below :
>
> 1) in applicationContext
>
>  <bean id="route" class="camelinaction.TestSpringManualStartup"/>
>
>    <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring";>
>        <routeBuilder ref="route"/>
>    </camelContext>
>
> 2)in route (java)
>
> public class TestSpringManualStartup extends RouteBuilder {
>
>         �...@override
>            public void configure() throws Exception {
>                // when the exchange is completed then stop the route by
>                // running this onCompletion
>                onCompletion().process(new StopRouteProcessor("manual"));
>
>                // ensure we only pickup one file at any given time
>                from("file://target/inventory/manual?maxMessagesPerPoll=1")
>                    // use noAutoStartup to indicate this route should
>                    // NOT be started when Camel starts
>                    .routeId("manual").noAutoStartup()
>          //          .log("Doing manual update with file ${file:name}")
>                    .split(body().tokenize("\n"))
>                    .convertBodyTo(UpdateInventoryInput.class)
>                    .to("direct:update");
>            }
>
>            public class StopRouteProcessor implements Processor {
>                private final String name;
>
>                public StopRouteProcessor(String name) {
>                    this.name = name;
>                }
>
>                public void process(Exchange exchange) throws Exception {
>                    exchange.getContext().stopRoute(name);
>                }
>            }
> }
>
>
>
> Thanks,
>
> Cyril
>
>
> --
> View this message in context: 
> http://old.nabble.com/Manually-start-route-in-java-code-tp28175201p28175201.html
> Sent from the Camel Development mailing list archive at Nabble.com.
>
>



-- 
Claus Ibsen
Apache Camel Committer

Author of Camel in Action: http://www.manning.com/ibsen/
Open Source Integration: http://fusesource.com
Blog: http://davsclaus.blogspot.com/
Twitter: http://twitter.com/davsclaus

Reply via email to