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