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.

Reply via email to