You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Claus Ibsen <cl...@gmail.com> on 2011/06/25 09:07:27 UTC
Re: reload routebuilder at runtime
On Fri, Jun 24, 2011 at 9:48 PM, fachhoch <fa...@gmail.com> wrote:
> ok in other words If my routebuilder is written in groovy using camel dsl
> ,will I be able to make changes and reload the routebuilder at runtime ?
>
You can use the API on CamelContext to update / add / remove routes etc.
> --
> View this message in context: http://camel.465427.n5.nabble.com/reload-routebuilder-at-runtime-tp4521292p4522087.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>
--
Claus Ibsen
-----------------
FuseSource
Email: cibsen@fusesource.com
Web: http://fusesource.com
Twitter: davsclaus, fusenews
Blog: http://davsclaus.blogspot.com/
Author of Camel in Action: http://www.manning.com/ibsen/
Re: reload routebuilder at runtime
Posted by Claus Ibsen <cl...@gmail.com>.
Ask the computer :)
For reloading .class files I guess you need something like JRebel or
the likes that support hot-reloading of .class files.
On Tue, Jun 28, 2011 at 5:15 PM, fachhoch <fa...@gmail.com> wrote:
> I saw the code fo DefaultCamelContext and I think I can use the method
>
>
> public synchronized void addRouteDefinitions(Collection<RouteDefinition>
> routeDefinitions) throws Exception {
> for (RouteDefinition routeDefinition : routeDefinitions) {
> removeRouteDefinition(routeDefinition);
> }
> this.routeDefinitions.addAll(routeDefinitions);
> if (shouldStartRoutes()) {
> startRouteDefinitions(routeDefinitions);
> }
> }
>
>
>
> My RouteBuilder will be a spring-groovy file , once I change the file
> spring will reload . I will use a servlet to update the camel context by
> calling addRouteDefinitions to which I will pass
> SpringApplicationContext.getBean("myrouteBuilder). getRouteCollection().
>
> what happens to the processor My routebuilder is this
>
> public class NearBatchFilesRouteBuilder extends RouteBuilder {
>
>
> public void configure() {
> from("file:///u01/oracle/artms-near/NEW?delay=60000&move=../PROCESSED")
> .convertBodyTo(String.class)
>
> .aggregate(constant(true)).completionSize(10).completionTimeout(10000L).groupExchanges()
> .process(new FileProcessor()).to("jms:queue:gov.hhs.newBatch.queue");
> }
>
> public static class FileProcessor implements Processor {
> @Override
> public void process(Exchange exchange) throws Exception {
> List<BatchFile> batchFiles=
> Lists.newArrayList(Iterables.transform(exchange.getProperty(Exchange.GROUPED_EXCHANGE,
> ArrayList.class), new Function<Exchange, BatchFile>() {
> @Override
> public BatchFile apply(Exchange input) {
> BatchFile batchFile= new BatchFile();
> String filename=(String)input.getIn().getHeader(Exchange.FILE_NAME);
> batchFile.setFileName(FilenameUtils.getName(filename));
> batchFile.setFiledata(input.getIn().getBody(String.class).getBytes());
> batchFile.setFileType(StringUtils.contains(filename,
> "tblACFReportInfo")? BatchFile.FileType.AUDIT:BatchFile.FileType.FINDING);
> return batchFile;
> }
> }));
> Batch
> batch=((BatchService)SpringApplicationContext.getBean("batchService")).createNewBatch(batchFiles);
> exchange.getIn().setBody(batch.getSysBatchId());
> }
> }
> }
>
>
>
> above class is a groovy file and I load this using <lang:groovy....../>
> at runtime I change the FileProcessor code and spring will reload
> this class, now I will access aservlet in the servlet I call
> camelContext.addRouteDefinitions(SpringApplicationContext.getBean("myrouteBuilder).
> getRouteCollection())
> this will reload the rootdefinitions but what happens to processor ? are
> they also get updated ?
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/reload-routebuilder-at-runtime-tp4521292p4532138.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>
--
Claus Ibsen
-----------------
FuseSource
Email: cibsen@fusesource.com
Web: http://fusesource.com
Twitter: davsclaus, fusenews
Blog: http://davsclaus.blogspot.com/
Author of Camel in Action: http://www.manning.com/ibsen/
Re: reload routebuilder at runtime
Posted by fachhoch <fa...@gmail.com>.
I saw the code fo DefaultCamelContext and I think I can use the method
public synchronized void addRouteDefinitions(Collection<RouteDefinition>
routeDefinitions) throws Exception {
for (RouteDefinition routeDefinition : routeDefinitions) {
removeRouteDefinition(routeDefinition);
}
this.routeDefinitions.addAll(routeDefinitions);
if (shouldStartRoutes()) {
startRouteDefinitions(routeDefinitions);
}
}
My RouteBuilder will be a spring-groovy file , once I change the file
spring will reload . I will use a servlet to update the camel context by
calling addRouteDefinitions to which I will pass
SpringApplicationContext.getBean("myrouteBuilder). getRouteCollection().
what happens to the processor My routebuilder is this
public class NearBatchFilesRouteBuilder extends RouteBuilder {
public void configure() {
from("file:///u01/oracle/artms-near/NEW?delay=60000&move=../PROCESSED")
.convertBodyTo(String.class)
.aggregate(constant(true)).completionSize(10).completionTimeout(10000L).groupExchanges()
.process(new FileProcessor()).to("jms:queue:gov.hhs.newBatch.queue");
}
public static class FileProcessor implements Processor {
@Override
public void process(Exchange exchange) throws Exception {
List<BatchFile> batchFiles=
Lists.newArrayList(Iterables.transform(exchange.getProperty(Exchange.GROUPED_EXCHANGE,
ArrayList.class), new Function<Exchange, BatchFile>() {
@Override
public BatchFile apply(Exchange input) {
BatchFile batchFile= new BatchFile();
String filename=(String)input.getIn().getHeader(Exchange.FILE_NAME);
batchFile.setFileName(FilenameUtils.getName(filename));
batchFile.setFiledata(input.getIn().getBody(String.class).getBytes());
batchFile.setFileType(StringUtils.contains(filename,
"tblACFReportInfo")? BatchFile.FileType.AUDIT:BatchFile.FileType.FINDING);
return batchFile;
}
}));
Batch
batch=((BatchService)SpringApplicationContext.getBean("batchService")).createNewBatch(batchFiles);
exchange.getIn().setBody(batch.getSysBatchId());
}
}
}
above class is a groovy file and I load this using <lang:groovy....../>
at runtime I change the FileProcessor code and spring will reload
this class, now I will access aservlet in the servlet I call
camelContext.addRouteDefinitions(SpringApplicationContext.getBean("myrouteBuilder).
getRouteCollection())
this will reload the rootdefinitions but what happens to processor ? are
they also get updated ?
--
View this message in context: http://camel.465427.n5.nabble.com/reload-routebuilder-at-runtime-tp4521292p4532138.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: reload routebuilder at runtime
Posted by Claus Ibsen <cl...@gmail.com>.
You may also want to take a look at
http://camel.apache.org/loading-routes-from-xml-files.html
On Tue, Jun 28, 2011 at 4:15 PM, Claus Ibsen <cl...@gmail.com> wrote:
> On Tue, Jun 28, 2011 at 4:08 PM, fachhoch <fa...@gmail.com> wrote:
>> what's the route id in my case? how can I find it ?
>>
>
> Look up in the phonebook :)
>
> Well joke aside. A route has an id. You can assign an explict id on a route
>
> <route id="foo">
> ...
> </route>
>
> And in Java code you use .routeId
>
> from("xxx").routeId("foo")...
>
> You can also get the routes from CamelContext as it has API to get the
> list of routes, so you can get the ids of the routes etc.
> Just take a look at the API a bit.
>
>>
>> --
>> View this message in context: http://camel.465427.n5.nabble.com/reload-routebuilder-at-runtime-tp4521292p4531888.html
>> Sent from the Camel - Users mailing list archive at Nabble.com.
>>
>
>
>
> --
> Claus Ibsen
> -----------------
> FuseSource
> Email: cibsen@fusesource.com
> Web: http://fusesource.com
> Twitter: davsclaus, fusenews
> Blog: http://davsclaus.blogspot.com/
> Author of Camel in Action: http://www.manning.com/ibsen/
>
--
Claus Ibsen
-----------------
FuseSource
Email: cibsen@fusesource.com
Web: http://fusesource.com
Twitter: davsclaus, fusenews
Blog: http://davsclaus.blogspot.com/
Author of Camel in Action: http://www.manning.com/ibsen/
Re: reload routebuilder at runtime
Posted by Claus Ibsen <cl...@gmail.com>.
On Tue, Jun 28, 2011 at 4:08 PM, fachhoch <fa...@gmail.com> wrote:
> what's the route id in my case? how can I find it ?
>
Look up in the phonebook :)
Well joke aside. A route has an id. You can assign an explict id on a route
<route id="foo">
...
</route>
And in Java code you use .routeId
from("xxx").routeId("foo")...
You can also get the routes from CamelContext as it has API to get the
list of routes, so you can get the ids of the routes etc.
Just take a look at the API a bit.
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/reload-routebuilder-at-runtime-tp4521292p4531888.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>
--
Claus Ibsen
-----------------
FuseSource
Email: cibsen@fusesource.com
Web: http://fusesource.com
Twitter: davsclaus, fusenews
Blog: http://davsclaus.blogspot.com/
Author of Camel in Action: http://www.manning.com/ibsen/
Re: reload routebuilder at runtime
Posted by fachhoch <fa...@gmail.com>.
what's the route id in my case? how can I find it ?
--
View this message in context: http://camel.465427.n5.nabble.com/reload-routebuilder-at-runtime-tp4521292p4531888.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: reload routebuilder at runtime
Posted by Claus Ibsen <cl...@gmail.com>.
You would have to remove a route first before you can add it (= update)
On Tue, Jun 28, 2011 at 3:54 PM, fachhoch <fa...@gmail.com> wrote:
> please tell me how to update a route using camel context I saw the api it
> has several methods , you have an example on updating a route at runtime ,
> my camel context is started by spring and routes registered
>
> here is my configration
>
> <camelContext id="camel"
> xmlns="http://camel.apache.org/schema/spring">
> <package>gov.hhs.acf.camel</package>
>
>
> <jmxAgent id="agent" createConnector="false"/>
> </camelContext>
>
>
> all the classes(Routebuilder) in the pacakge gov.hhs.acf.camel are loaded
> by camle context now at runtime I want to update one routebuilder , please
> tell me how , I did not see a method as update route , it has addroute,
> stoproute etc.
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/reload-routebuilder-at-runtime-tp4521292p4531857.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>
--
Claus Ibsen
-----------------
FuseSource
Email: cibsen@fusesource.com
Web: http://fusesource.com
Twitter: davsclaus, fusenews
Blog: http://davsclaus.blogspot.com/
Author of Camel in Action: http://www.manning.com/ibsen/
Re: reload routebuilder at runtime
Posted by fachhoch <fa...@gmail.com>.
please tell me how to update a route using camel context I saw the api it
has several methods , you have an example on updating a route at runtime ,
my camel context is started by spring and routes registered
here is my configration
<camelContext id="camel"
xmlns="http://camel.apache.org/schema/spring">
<package>gov.hhs.acf.camel</package>
<jmxAgent id="agent" createConnector="false"/>
</camelContext>
all the classes(Routebuilder) in the pacakge gov.hhs.acf.camel are loaded
by camle context now at runtime I want to update one routebuilder , please
tell me how , I did not see a method as update route , it has addroute,
stoproute etc.
--
View this message in context: http://camel.465427.n5.nabble.com/reload-routebuilder-at-runtime-tp4521292p4531857.html
Sent from the Camel - Users mailing list archive at Nabble.com.