Hi

Yeah kamelet expects sink | source as endpoints as its for kamelets.
You cannot use it for general route templates like your example with timer.
Also your route template is wrong as its a source, (eg from timer) that you
cannot "call" from a route

No jira as kamelet component is for kamelets so it expects kamelet:source
or kamelet:sink style route templates.



On Mon, Jul 25, 2022 at 9:28 AM ski n <[email protected]> wrote:

> Hi Claus,
>
> I just test this and indeed this already works better with the latest
> 3.18.0.
>
> The template is recognized (I do think that most users expect autodiscovery
> for route templates btw)
>
> Now I get:
>
> org.apache.camel.component.kamelet.KameletConsumerNotAvailableException: No
> consumers available on endpoint: kamelet://sink?routeId=myTemplate-2.
> Exchange[CBBC99C88C35310-0000000000000003]
>         at
>
> org.apache.camel.component.kamelet.KameletProducer.process(KameletProducer.java:78)
>         at
> org.apache.camel.processor.SendProcessor.process(SendProcessor.java:172)
>         at
>
> org.apache.camel.processor.errorhandler.RedeliveryErrorHandler$SimpleTask.run(RedeliveryErrorHandler.java:471)
>         at
>
> org.apache.camel.impl.engine.DefaultReactiveExecutor$Worker.schedule(DefaultReactiveExecutor.java:189)
>         at
>
> org.apache.camel.impl.engine.DefaultReactiveExecutor.scheduleMain(DefaultReactiveExecutor.java:61)
>         at org.apache.camel.processor.Pipeline.process(Pipeline.java:184)
>         at
>
> org.apache.camel.impl.engine.CamelInternalProcessor.process(CamelInternalProcessor.java:399)
>         at
>
> org.apache.camel.component.timer.TimerConsumer.sendTimerExchange(TimerConsumer.java:210)
>         at
> org.apache.camel.component.timer.TimerConsumer$1.run(TimerConsumer.java:76)
>         at java.base/java.util.TimerThread.mainLoop(Timer.java:556)
>         at java.base/java.util.TimerThread.run(Timer.java:506)
>
> I think Kamelets assume something like "kamelet:source" or "kamel:sink". I
> only use the route template of course:
>
> 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}");
>
> Shall I make a Jira for this?
>
> Raymond
>
>
>
>
>
> On Mon, Jul 25, 2022 at 8:47 AM Claus Ibsen <[email protected]> wrote:
>
> > Hi
> >
> > You are using a bit old Camel version, try with 3.18.x as route template
> > and kamelets keep improving going forward.
> >
> > The kamelet component will first look in camel content if a route
> template
> > with the given id exists, and use it as-is.
> > And if not, then it tries to load it via yaml kamelet files.
> >
> > So in your use case if you manually load the templates and ensure it is
> all
> > correct then there is a chance that you can "misuse" the kamelet
> component.
> > But use latest version.
> >
> > On Mon, Jul 25, 2022 at 8:21 AM ski n <[email protected]> wrote:
> >
> > > 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 <[email protected]>
> > 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 <[email protected]>
> > 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
> > > >
> > >
> >
> >
> > --
> > Claus Ibsen
> > -----------------
> > http://davsclaus.com @davsclaus
> > Camel in Action 2: https://www.manning.com/ibsen2
> >
>


-- 
Claus Ibsen
-----------------
http://davsclaus.com @davsclaus
Camel in Action 2: https://www.manning.com/ibsen2

Reply via email to