OK, thanks (this was more or less what I was trying to avoid :) )

I thought that this is possible based on the documentation:

https://camel.apache.org/components/next/kamelet-component.html

" The Kamelet Component provides support for interacting with the Camel
Route Template <https://camel.apache.org/manual/route-template.html> engine
using Endpoint semantic. "

And later it says:

"Configuring components can be done with the Component DSL
<https://camel.apache.org/manual/component-dsl.html>, in a configuration
file (application.properties|yaml), or directly with Java code."

For me, it's not really clear what 'interacting with the Camel Route
Template' and 'configuring' means? Why do I need the extra initiation step
in between?
I thought I configure it directly by using it in a route through endpoint
semantics?

Are there plans to make it possible like I described in the previous post
(thus without YAML)? I am already using the Java DSL and XML DSL and I
don't want to use the YAML DSL as well.

My goal is to define the template through the Java API

and

then let users write a route and call it to use only endpoint semantic. I
do not know what values the user will use (that's why I parameterized them)
and the user doesn't know anything about templates.

I guess I could write a preprocessor, but that's a bit beyond the purpose
of avoiding the current preprocessing (I have a web application and get the
route configuration as JSON and then convert it to an XML route). The goal
was to make this process easier :)

Raymond





On Mon, Jul 25, 2022 at 7:37 AM Claus Ibsen <claus.ib...@gmail.com> wrote:

> Hi
>
> Kamelets and route templates are not 100% the same, so what you do is not
> possible.
>
> The kamelet component (eg to("kamelet:xxx") is for kamelets, that are yaml
> files with metadata and an embedded route template (flow)
> https://github.com/apache/camel-kamelets
>
> With route templates, you need to use the java api, to add a route from a
> template, and give it some id, and parameters.
> And then from your route that wants to call then use direct:xxx to call the
> new route.
>
>
>
> On Sun, Jul 24, 2022 at 11:19 PM ski n <raymondmees...@gmail.com> wrote:
>
> > Hi,
> >
> > I have a Camel routeTemplate like this:
> >
> > public class MyRouteTemplates extends RouteBuilder {
> >
> >     @Override
> >     public void configure() throws Exception {
> >         // create a route template with the given name
> >         routeTemplate("myTemplate")
> >             // here we define the required input parameters (can have
> > default values)
> >             .templateParameter("name")
> >             .templateParameter("greeting")
> >             .templateParameter("myPeriod", "3s")
> >             // here comes the route in the template
> >             // notice how we use {{name}} to refer to the template
> > parameters
> >             // we can also use {{propertyName}} to refer to property
> > placeholders
> >             .from("timer:{{name}}?period={{myPeriod}}")
> >                 .setBody(simple("{{greeting}} ${body}"))
> >                 .log("${body}");
> >     }
> > }
> >
> > And I like to call it from a route as a Kamelet like this:
> >
> > from("direct:a")
> >   .to("kamelet:myTemplate?someparameters")
> >
> > How to make "myTemplate" available to the CamelContext?
> >
> >
> > I saw in camel-examples that is using camel-main that you can do it like
> > this:
> >
> >         Main main = new Main();
> >         main.configure().addRoutesBuilder(MyRouteTemplates.class);
> >
> > However I am not using main, but Camel core. So I tried it like:
> >
> > MyRouteTemplates myRouteTemplates = new new MyRouteTemplates();
> > myRouteTemplates.addRoutesToCamelContext(context);
> >
> > or
> >
> > context.addRoutes(myRouteTemplates);
> >
> >
> > However I get
> "org.apache.camel.component.kamelet.KameletNotFoundException:
> > Kamelet with id myTemplate not found in locations: classpath:/kamelets".
> >
> > This was using Camel 3.14.4
> >
> > What is the correct way to register/load routeTemplate so they can used
> by
> > a Kamelet endpoint?
> >
> > Raymond
> >
>
>
> --
> Claus Ibsen
> -----------------
> http://davsclaus.com @davsclaus
> Camel in Action 2: https://www.manning.com/ibsen2
>

Reply via email to