You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@camel.apache.org by CyrilForce <lu...@hotmail.com> on 2010/04/08 09:41:25 UTC

Manually start route in java code

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.


Re: Manually start route in java code

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

See this unit test
https://svn.apache.org/repos/asf/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/CamelContextAutoStartupTest.java



On Fri, Apr 9, 2010 at 8:35 AM, CyrilForce <lu...@hotmail.com> wrote:
>
> Hi Claus,
>
>  First of all i would like to thank you for your quick response. Secondly i
> would like to ask you is that possible to execute the following code :
>
> 1) java
>
>                ApplicationContext context = new
> ClassPathXmlApplicationContext("InvokeWithSpringOnly.xml");
>                CamelContext cc = (CamelContext)context.getBean("camel");
>                cc.start();
>
>                 Thread.sleep(10000);
>
>               // stop the CamelContext
>               cc.stop();
>
> 2)Spring
>
>    <bean id="hello" class="camelinaction.HelloBean"/>
>    <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
>    <route>
>
>                <from uri="direct:start"/>
>                <bean ref="hello"/>
>            <to uri="seda:bar?concurrentConsumers=5"/>
>
>    </route>
>        </camelContext>
>
> whereby the hello bean is just some println. However i unable to get the
> println in console. Besides this question, i would like to also is that
> camelContext able to use in spring 3.0 ? because i was getting unable to
> locate namespace  camelContext even i include the path
> (http://camel.apache.org/schema/spring
> http://camel.apache.org/schema/spring/camel-spring.xsd) in
> xsi:schemaLocation.
>
> Thanks
>
> Regards,
>
> Cyril
>
>
>
>
> --
> View this message in context: http://old.nabble.com/Manually-start-route-in-java-code-tp28175201p28188199.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

Re: Manually start route in java code

Posted by CyrilForce <lu...@hotmail.com>.
Hi Claus,

 First of all i would like to thank you for your quick response. Secondly i
would like to ask you is that possible to execute the following code :

1) java 

		ApplicationContext context = new
ClassPathXmlApplicationContext("InvokeWithSpringOnly.xml");
                CamelContext cc = (CamelContext)context.getBean("camel");
		cc.start();

		 Thread.sleep(10000);

	       // stop the CamelContext
	       cc.stop();

2)Spring 

    <bean id="hello" class="camelinaction.HelloBean"/>
    <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
    <route>

		<from uri="direct:start"/>
	        <bean ref="hello"/>
	    <to uri="seda:bar?concurrentConsumers=5"/>
        
    </route>
	</camelContext>

whereby the hello bean is just some println. However i unable to get the
println in console. Besides this question, i would like to also is that
camelContext able to use in spring 3.0 ? because i was getting unable to
locate namespace  camelContext even i include the path
(http://camel.apache.org/schema/spring
http://camel.apache.org/schema/spring/camel-spring.xsd) in
xsi:schemaLocation.

Thanks 

Regards, 

Cyril




-- 
View this message in context: http://old.nabble.com/Manually-start-route-in-java-code-tp28175201p28188199.html
Sent from the Camel Development mailing list archive at Nabble.com.


Re: Manually start route in java code

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

You need to start Spring first
context.start();

And then you should be able to start the route when you want.


On Thu, Apr 8, 2010 at 11:28 AM, CyrilForce <lu...@hotmail.com> wrote:
>
> Hi Claus,
>
> I had tried with following code :
>
> public class UseSpring
> {
>        public static void main(String args[]) throws Exception
>        {
>                ApplicationContext context = new
> ClassPathXmlApplicationContext("TestSpring.xml");
>
>                CamelContext cc = (CamelContext)context.getBean("camel");
>                cc.startRoute("manual");
>
>        }
>
> }
>
> But it says :
>
> 2010-04-08 17:26:24,243 [main           ] INFO  DefaultCamelContext
> - Apache Camel 2.1.0 (CamelContext:camel) is starting
> 2010-04-08 17:26:24,245 [main           ] INFO  DefaultCamelContext
> - JMX enabled. Using DefaultManagedLifecycleStrategy.
> 2010-04-08 17:26:24,645 [main           ] INFO  DefaultCamelContext
> - Cannot start route manual as it is configured with auto startup disabled.
> 2010-04-08 17:26:24,645 [main           ] INFO  DefaultCamelContext
> - Apache Camel 2.1.0 (CamelContext:camel) started
>
> Thanks
>
> Cyril
>
>
>
>
>
> Claus Ibsen-2 wrote:
>>
>> On Thu, Apr 8, 2010 at 10:40 AM, CyrilForce <lu...@hotmail.com> wrote:
>>>
>>> Hi Claus,
>>>
>>> As refer to the book in Chapter 13 page 256, It mention (CamelContext
>>> also
>>> provides a startRoute method for starting a route). How do i able to get
>>> the
>>> CamelContext in java code assume that i wanted to fire up the route in a
>>> servlet?
>>>
>>
>> CamelContext is just another spring bean, so use Spring dependency
>> stuff to provide the CamelContext
>>
>> <camelContext id="myCamel" ..>
>>
>> Then its just a bean with id = myCamel
>>
>>
>> See this old tutorial using a servlet and spring dependency to get camel
>> http://camel.apache.org/tutorial-axis-camel.html
>>
>>>
>>> Thanks,
>>>
>>> Cyril
>>>
>>>
>>>
>>>
>>>
>>> Claus Ibsen-2 wrote:
>>>>
>>>> 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 <lu...@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
>>>>
>>>>
>>>
>>> --
>>> View this message in context:
>>> http://old.nabble.com/Manually-start-route-in-java-code-tp28175201p28175762.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
>>
>>
>
> --
> View this message in context: http://old.nabble.com/Manually-start-route-in-java-code-tp28175201p28176183.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

Re: Manually start route in java code

Posted by CyrilForce <lu...@hotmail.com>.
Hi Claus,

I had tried with following code :

public class UseSpring 
{
	public static void main(String args[]) throws Exception
	{
		ApplicationContext context = new
ClassPathXmlApplicationContext("TestSpring.xml");
		
		CamelContext cc = (CamelContext)context.getBean("camel");
		cc.startRoute("manual");

	}

}

But it says :

2010-04-08 17:26:24,243 [main           ] INFO  DefaultCamelContext           
- Apache Camel 2.1.0 (CamelContext:camel) is starting
2010-04-08 17:26:24,245 [main           ] INFO  DefaultCamelContext           
- JMX enabled. Using DefaultManagedLifecycleStrategy.
2010-04-08 17:26:24,645 [main           ] INFO  DefaultCamelContext           
- Cannot start route manual as it is configured with auto startup disabled.
2010-04-08 17:26:24,645 [main           ] INFO  DefaultCamelContext           
- Apache Camel 2.1.0 (CamelContext:camel) started

Thanks

Cyril





Claus Ibsen-2 wrote:
> 
> On Thu, Apr 8, 2010 at 10:40 AM, CyrilForce <lu...@hotmail.com> wrote:
>>
>> Hi Claus,
>>
>> As refer to the book in Chapter 13 page 256, It mention (CamelContext
>> also
>> provides a startRoute method for starting a route). How do i able to get
>> the
>> CamelContext in java code assume that i wanted to fire up the route in a
>> servlet?
>>
> 
> CamelContext is just another spring bean, so use Spring dependency
> stuff to provide the CamelContext
> 
> <camelContext id="myCamel" ..>
> 
> Then its just a bean with id = myCamel
> 
> 
> See this old tutorial using a servlet and spring dependency to get camel
> http://camel.apache.org/tutorial-axis-camel.html
> 
>>
>> Thanks,
>>
>> Cyril
>>
>>
>>
>>
>>
>> Claus Ibsen-2 wrote:
>>>
>>> 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 <lu...@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
>>>
>>>
>>
>> --
>> View this message in context:
>> http://old.nabble.com/Manually-start-route-in-java-code-tp28175201p28175762.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
> 
> 

-- 
View this message in context: http://old.nabble.com/Manually-start-route-in-java-code-tp28175201p28176183.html
Sent from the Camel Development mailing list archive at Nabble.com.


Re: Manually start route in java code

Posted by Claus Ibsen <cl...@gmail.com>.
On Thu, Apr 8, 2010 at 10:40 AM, CyrilForce <lu...@hotmail.com> wrote:
>
> Hi Claus,
>
> As refer to the book in Chapter 13 page 256, It mention (CamelContext also
> provides a startRoute method for starting a route). How do i able to get the
> CamelContext in java code assume that i wanted to fire up the route in a
> servlet?
>

CamelContext is just another spring bean, so use Spring dependency
stuff to provide the CamelContext

<camelContext id="myCamel" ..>

Then its just a bean with id = myCamel


See this old tutorial using a servlet and spring dependency to get camel
http://camel.apache.org/tutorial-axis-camel.html

>
> Thanks,
>
> Cyril
>
>
>
>
>
> Claus Ibsen-2 wrote:
>>
>> 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 <lu...@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
>>
>>
>
> --
> View this message in context: http://old.nabble.com/Manually-start-route-in-java-code-tp28175201p28175762.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

Re: Manually start route in java code

Posted by CyrilForce <lu...@hotmail.com>.
Hi Claus,

As refer to the book in Chapter 13 page 256, It mention (CamelContext also
provides a startRoute method for starting a route). How do i able to get the
CamelContext in java code assume that i wanted to fire up the route in a
servlet? 


Thanks,

Cyril





Claus Ibsen-2 wrote:
> 
> 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 <lu...@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
> 
> 

-- 
View this message in context: http://old.nabble.com/Manually-start-route-in-java-code-tp28175201p28175762.html
Sent from the Camel Development mailing list archive at Nabble.com.


Re: Manually start route in java code

Posted by Claus Ibsen <cl...@gmail.com>.
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 <lu...@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