Extensible Camel routes

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Extensible Camel routes

Burkard Stephan
Hi Camel users

Let's say I have this generic file to JMS route I would like to put in a library.

from(directory?options...)
   .routeId("basicFileToJmsRoute")
   .log(LoggingLevel.INFO, "[FILEREADER], file: ${in.header.CamelFileName}")
   .to(queueEndpointUri);


Then I would like to build multiple modules who use the route where each module has its own configuration (directory, queue etc).

But some of them have also additional requirements, for example split large XML files:

from(directory?options...)
   .routeId("basicFileToJmsRoute")
   .log(LoggingLevel.INFO, "[FILEREADER], file: ${in.header.CamelFileName}")
=>   .split().tokenizeXML(SPLITTER_ELEMENT_NAME).streaming()
   .to(queueEndpointUri);


Is there a best practice approach to extend a basic route like this in another module?

Thanks
Stephan

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Extensible Camel routes

Claus Ibsen-2
Hi

A RouteBuilder is essentially just java, so you can create base
classes / abstract classes and have getter/setter (or what you prefer)
for configuration.

You can also use java's if .. else .. etc to add parts to the route if
you need. You can then put the routes together using the model classes
(the xxxDefinition).

But try to not make this to complex / confusing to maintain. You may
want to have special routes for splitter vs non splitter etc.


On Thu, Apr 20, 2017 at 11:04 AM, Burkard Stephan
<[hidden email]> wrote:

> Hi Camel users
>
> Let's say I have this generic file to JMS route I would like to put in a library.
>
> from(directory?options...)
>    .routeId("basicFileToJmsRoute")
>    .log(LoggingLevel.INFO, "[FILEREADER], file: ${in.header.CamelFileName}")
>    .to(queueEndpointUri);
>
>
> Then I would like to build multiple modules who use the route where each module has its own configuration (directory, queue etc).
>
> But some of them have also additional requirements, for example split large XML files:
>
> from(directory?options...)
>    .routeId("basicFileToJmsRoute")
>    .log(LoggingLevel.INFO, "[FILEREADER], file: ${in.header.CamelFileName}")
> =>   .split().tokenizeXML(SPLITTER_ELEMENT_NAME).streaming()
>    .to(queueEndpointUri);
>
>
> Is there a best practice approach to extend a basic route like this in another module?
>
> Thanks
> Stephan
>



--
Claus Ibsen
-----------------
http://davsclaus.com @davsclaus
Camel in Action 2: https://www.manning.com/ibsen2
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Extensible Camel routes

Quinn Stevenson
This isn’t quite you’re use case since I don’t extend routes, but I have RouteBuilders that I deploy hundreds of times with different configurations using either camel-blueprint, camel-scr and Blueprint namespace handlers.

I allow minor variations the routes based on the configuration of the RouteBuilder, so if I were going to try your example, the configure method would look something like this:

public void configure() throws Exception {
  ProcessorDefinition<?> routeDef =
      from("file://").routeId(routeId)
          .log(LoggingLevel.INFO, "[FILEREADER], file: ${in.header.CamelFileName}");

  if (SPLITTER_ELEMENT_NAME != null && !SPLITTER_ELEMENT_NAME.isEmpty()) {
    routeDef = routeDef.split().tokenizeXML(SPLITTER_ELEMENT_NAME).streaming()
  }

  routeDef.to(queueEndpointUri);
}
Notice that If the SPLITTER_ELEMENT_NAME property is set, then the route will include the “split”.

I’ve used this technique quite a bit, and I’ll reiterate the comment Claus made about complexity - be careful with this.  MINOR variations of the route are supportable, but too many allowed variations can make the RouteBuilder very difficult to support.

HTH




> On Apr 20, 2017, at 3:25 AM, Claus Ibsen <[hidden email]> wrote:
>
> Hi
>
> A RouteBuilder is essentially just java, so you can create base
> classes / abstract classes and have getter/setter (or what you prefer)
> for configuration.
>
> You can also use java's if .. else .. etc to add parts to the route if
> you need. You can then put the routes together using the model classes
> (the xxxDefinition).
>
> But try to not make this to complex / confusing to maintain. You may
> want to have special routes for splitter vs non splitter etc.
>
>
> On Thu, Apr 20, 2017 at 11:04 AM, Burkard Stephan
> <[hidden email]> wrote:
>> Hi Camel users
>>
>> Let's say I have this generic file to JMS route I would like to put in a library.
>>
>> from(directory?options...)
>>   .routeId("basicFileToJmsRoute")
>>   .log(LoggingLevel.INFO, "[FILEREADER], file: ${in.header.CamelFileName}")
>>   .to(queueEndpointUri);
>>
>>
>> Then I would like to build multiple modules who use the route where each module has its own configuration (directory, queue etc).
>>
>> But some of them have also additional requirements, for example split large XML files:
>>
>> from(directory?options...)
>>   .routeId("basicFileToJmsRoute")
>>   .log(LoggingLevel.INFO, "[FILEREADER], file: ${in.header.CamelFileName}")
>> =>   .split().tokenizeXML(SPLITTER_ELEMENT_NAME).streaming()
>>   .to(queueEndpointUri);
>>
>>
>> Is there a best practice approach to extend a basic route like this in another module?
>>
>> Thanks
>> Stephan
>>
>
>
>
> --
> Claus Ibsen
> -----------------
> http://davsclaus.com @davsclaus
> Camel in Action 2: https://www.manning.com/ibsen2

Loading...