Hi Raymond, Can't be a Kamelet considered for such a feature? I think it's one of its purposes as well.
Pasquale. On Mon, Jan 8, 2024 at 3:21 PM ski n <raymondmees...@gmail.com> wrote: > Question/Discussion: > > Do you think "functions" in the Camel DSL make sense? > > Explanation: > > Say you have to following route: > > from("direct:a") > .setHeader("myHeader", constant("test")) > .to("direct:b"); > > And then you have a similar route: > > from("direct:c") > .setHeader("myHeader2", constant("test")) > .to("direct:d"); > > As you are setting it more or less the same you could make a routeTemplate: > > routeTemplate("someFunction") > // here we define the required input parameters (with a default > value) > .templateParameter("headerName", "myHeader") > .from("direct:a") > .setHeader("{{headerName}}", constant("test")) > > And then you can: > > from("direct:a") > .to("direct:someFunction") > .to("direct:b"); > > And for the second route: > > from("direct:c") > .to("direct:someFunction") > .to("direct:d"); > > > This however seems a bit cumbersome, because: > > 1. I must have a from statement in my subroute (which should be just a > function). > 2. I need to know the component of the from statement and call it with a > "to" statement. > 3. I need to create the route from routeTemplates before the route starts > and I need to do this everytime I use that 'function'. > 4. If I want to use the same code then I need to call the same route > multiple times, > but in certain cases this can become a bottle-neck (think of Seda of JMS > Queues). > Especially when call it from hundreds of places, this maybe troublesome > (throughput or memory). > > > Would be easier and more direct to have like this: > > function("someFunction") > .parameter("headerName", "myHeader") > .setHeader("{{headerName}}", constant("test")) > > And then call it: > > from("direct:a") > .function("someFunction") > .to("direct:b"); > > And: > > from("direct:c") > .function("someFunction") > .parameter("myHeader2") > .to("direct:d"); > > On install the routes are exactly the same as the first and second route > (only reused). > > What do think? > > Raymond >