You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by tkatva <tu...@gmail.com> on 2011/10/29 07:26:39 UTC
Creating routes dynamically
Hi
I am newbie with Camel and it seems to be very powerful framework. One thing
that I haven't found out yet is that how can you create routes
programmatically/dynamically?
So let's say I created following code :
camel = new DefaultCamelContext();
camel.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
from("file:C:\\FtpTestFolders\\FtpOut?delete=true")
.setHeader(Exchange.FILE_NAME,
constant("TestiPrkl.txt"))
.to("file:C:\\FtpTestFolders\\FtpIn")
.setHeader(Exchange.FILE_NAME,
constant("ToinenTestiPrkl.txt"))
.to("file:C:\\FtpTestFolders\\FtpError");
//Here I may or may not want to add other headers,
endpoints and processors
}
});
This is fine but what if I have defined my headers and endpoint in somewhere
else (db/file/etc) and I wan't to create routes based on these dynamically.
The API is quite complex so if someone could post me an example I would
really appreciate it.
Thank you
--
View this message in context: http://camel.465427.n5.nabble.com/Creating-routes-dynamically-tp4948062p4948062.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: Creating routes dynamically
Posted by Donald Whytock <dw...@gmail.com>.
Be advised, some of the strings used inside RouteBuilder are expected
to be final variables.
Some things about routes can be changed even after they've been
created. Check out DelegateProcessor.
Don
On Sun, Oct 30, 2011 at 3:52 AM, Claus Ibsen <cl...@gmail.com> wrote:
> On Sat, Oct 29, 2011 at 7:26 PM, Johm Mac <mc...@gmail.com> wrote:
>> The endpoints are strings - nothing prevents you from externalising such
>> information (say in a config file) and then build the endpoint urls based on
>> values in there that you read in at start-up time. Processors can be
>> equally created 'late'. If the class you are using has state you can
>> insantiate it from within the routebuilder also
>>
>> Let me know if you need something more concrete - hopefully this makes sense
>>
>
> Also the RouteBuilder configure method is just java code. So you can
> have for loops, if .. else etc. And thus
> create a route template, to use to create new dynamic routes.
>
>
>
>> On 29/10/2011 06:26, tkatva wrote:
>>>
>>> Hi
>>>
>>>
>>> I am newbie with Camel and it seems to be very powerful framework. One
>>> thing
>>> that I haven't found out yet is that how can you create routes
>>> programmatically/dynamically?
>>>
>>> So let's say I created following code :
>>>
>>> camel = new DefaultCamelContext();
>>> camel.addRoutes(new RouteBuilder() {
>>> @Override
>>> public void configure() throws Exception {
>>>
>>> from("file:C:\\FtpTestFolders\\FtpOut?delete=true")
>>>
>>> .setHeader(Exchange.FILE_NAME,
>>> constant("TestiPrkl.txt"))
>>> .to("file:C:\\FtpTestFolders\\FtpIn")
>>> .setHeader(Exchange.FILE_NAME,
>>> constant("ToinenTestiPrkl.txt"))
>>> .to("file:C:\\FtpTestFolders\\FtpError");
>>> //Here I may or may not want to add other headers,
>>> endpoints and processors
>>>
>>> }
>>> });
>>>
>>> This is fine but what if I have defined my headers and endpoint in
>>> somewhere
>>> else (db/file/etc) and I wan't to create routes based on these
>>> dynamically.
>>> The API is quite complex so if someone could post me an example I would
>>> really appreciate it.
>>>
>>> Thank you
>>>
>>> --
>>> View this message in context:
>>> http://camel.465427.n5.nabble.com/Creating-routes-dynamically-tp4948062p4948062.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: Creating routes dynamically
Posted by Claus Ibsen <cl...@gmail.com>.
On Sat, Oct 29, 2011 at 7:26 PM, Johm Mac <mc...@gmail.com> wrote:
> The endpoints are strings - nothing prevents you from externalising such
> information (say in a config file) and then build the endpoint urls based on
> values in there that you read in at start-up time. Processors can be
> equally created 'late'. If the class you are using has state you can
> insantiate it from within the routebuilder also
>
> Let me know if you need something more concrete - hopefully this makes sense
>
Also the RouteBuilder configure method is just java code. So you can
have for loops, if .. else etc. And thus
create a route template, to use to create new dynamic routes.
> On 29/10/2011 06:26, tkatva wrote:
>>
>> Hi
>>
>>
>> I am newbie with Camel and it seems to be very powerful framework. One
>> thing
>> that I haven't found out yet is that how can you create routes
>> programmatically/dynamically?
>>
>> So let's say I created following code :
>>
>> camel = new DefaultCamelContext();
>> camel.addRoutes(new RouteBuilder() {
>> @Override
>> public void configure() throws Exception {
>>
>> from("file:C:\\FtpTestFolders\\FtpOut?delete=true")
>>
>> .setHeader(Exchange.FILE_NAME,
>> constant("TestiPrkl.txt"))
>> .to("file:C:\\FtpTestFolders\\FtpIn")
>> .setHeader(Exchange.FILE_NAME,
>> constant("ToinenTestiPrkl.txt"))
>> .to("file:C:\\FtpTestFolders\\FtpError");
>> //Here I may or may not want to add other headers,
>> endpoints and processors
>>
>> }
>> });
>>
>> This is fine but what if I have defined my headers and endpoint in
>> somewhere
>> else (db/file/etc) and I wan't to create routes based on these
>> dynamically.
>> The API is quite complex so if someone could post me an example I would
>> really appreciate it.
>>
>> Thank you
>>
>> --
>> View this message in context:
>> http://camel.465427.n5.nabble.com/Creating-routes-dynamically-tp4948062p4948062.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: Creating routes dynamically
Posted by Johm Mac <mc...@gmail.com>.
The endpoints are strings - nothing prevents you from externalising such
information (say in a config file) and then build the endpoint urls
based on values in there that you read in at start-up time. Processors
can be equally created 'late'. If the class you are using has state you
can insantiate it from within the routebuilder also
Let me know if you need something more concrete - hopefully this makes sense
On 29/10/2011 06:26, tkatva wrote:
> Hi
>
>
> I am newbie with Camel and it seems to be very powerful framework. One thing
> that I haven't found out yet is that how can you create routes
> programmatically/dynamically?
>
> So let's say I created following code :
>
> camel = new DefaultCamelContext();
>
>
>
> camel.addRoutes(new RouteBuilder() {
>
>
> @Override
> public void configure() throws Exception {
>
>
> from("file:C:\\FtpTestFolders\\FtpOut?delete=true")
>
> .setHeader(Exchange.FILE_NAME,
> constant("TestiPrkl.txt"))
> .to("file:C:\\FtpTestFolders\\FtpIn")
> .setHeader(Exchange.FILE_NAME,
> constant("ToinenTestiPrkl.txt"))
> .to("file:C:\\FtpTestFolders\\FtpError");
> //Here I may or may not want to add other headers,
> endpoints and processors
>
>
> }
>
> });
>
> This is fine but what if I have defined my headers and endpoint in somewhere
> else (db/file/etc) and I wan't to create routes based on these dynamically.
> The API is quite complex so if someone could post me an example I would
> really appreciate it.
>
> Thank you
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Creating-routes-dynamically-tp4948062p4948062.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
Re: Creating routes dynamically
Posted by tkatva <tu...@gmail.com>.
Also being able to add processors to each target endpoint would be
necessary...
--
View this message in context: http://camel.465427.n5.nabble.com/Creating-routes-dynamically-tp4948062p4948350.html
Sent from the Camel - Users mailing list archive at Nabble.com.