camel-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Claus Ibsen <claus.ib...@gmail.com>
Subject Re: Manually start route in java code
Date Thu, 08 Apr 2010 08:44:26 GMT
On Thu, Apr 8, 2010 at 10:40 AM, CyrilForce <lum_hoo@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 <lum_hoo@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

Mime
View raw message