I also seem to recall that routeTemplates haven't all functionality from Kamelets, and you can't call all routeTemplates exactly the same from the Kamelet component, but maybe this is not a limitation anymore.
btw In my own runtime (Assimbly) I do load all Kamelets by default, so they are straight to use. Raymond On Mon, Jan 8, 2024 at 4:24 PM ski n <raymondmees...@gmail.com> wrote: > Yeah, calling a Kamelet has the advantage that the subroute is dynamically > created. > > - Still need the to, not a separate EIP. > - Beginners would not search for "Kamelet", but function would be more > common > - You still need a from statement within the Kamelet > - Kamelet is not really part of the route, but a separate (sub)route > > But yeah this comes close. Maybe just call it with > function("template").parameters() or routeTemplate("").parameters() in > the DSL would be enough for most. > > Raymond > > > > > > > On Mon, Jan 8, 2024 at 4:00 PM Andrea Cosentino <anco...@gmail.com> wrote: > >> It really seems the Kamelets' mission >> >> Il lun 8 gen 2024, 15:59 Pasquale Congiusti <pasquale.congiu...@gmail.com >> > >> ha scritto: >> >> > 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 >> > > >> > >> >