Thank you Claus for your reply. 
Just wondering though, according to this page: 
https://camel.apache.org/releases/ version 3.22.4 is LTS and was built March 9, 
2025. Are you still saying that all versions of Camel 3 are EOL?

In the meantime, we did a quick try with Camel 4.x.x. for this problem.
Daniel, my colleague, did a test with Camel 4.10.0 and SB-3.1.8 and we do NOT 
see this problem there. So that's news there and it seems specific then to 
3.22.4.
We also thought about it possibly as a timing and/or order of operations 
problem.
So, we tried to a) add a delay after the route templates are created and before 
they are used, b) add SB annotation @DependsOn - but neither of these worked.
From the "light" debugging we did, we see that the list used by the 
RoutesConfigurer class doesn't have the same content. If you're interested we 
could provide some trace/debug logs for you ;-)

thanks,
jvh/dg



________________________________________
From: Claus Ibsen <claus.ib...@gmail.com>
Sent: June 9, 2025 10:01 AM
To: users@camel.apache.org
Subject: Re: creating route template - java builder vrs java dsl

Hi

We have not heard about this before.
Camel 3 is EOL and not supported.

You are welcome to try with the latest Camel v4 and see if you can find out
if something is still wrong or not.

Also mind SB has package scanning so your problem is likely something about
SB loading some clases before others and you end up with the templates not
loaded before the code you do that uses the template.
Maybe there is some SB annotation trick to declare dependency order among
the beans and whatnot.

But Camel 3 is EOL and we wont have time to investigate old releases.


On Fri, Jun 6, 2025 at 7:44 PM j vh <jvh...@hotmail.com> wrote:

> Hello,
> We are upgrading from Camel 3.18.4 to 3.22.4 to pickup some important bug
> fixes but noticed a new problem. When we are instantiating a route in a
> spring-boot (2.6.2) app from a route-template the Java builder
> intermittently fails 3 out of 4 times. As a workaround we switched to using
> the Java DSL way to create the route and this seems to work fine.
>
> This Java DSL code works:
>
> final TemplatedRouteDefinition route = templatedRoute("template1")
>               .routeId("route-template1-id")
>               .parameter("param1", queueName)
>               .parameter("param2", restApiEndpoint));
>       LOG.info("buildTemplatedRoute() created templated route: {}",
> route.getRouteId());
>
> But this Java builder code fails intermittently (3 out of 4 times):
>
>       final String route = TemplatedRouteBuilder.builder(camelContext,
> "template1")
>               .routeId("route-template1-id")
>               .parameter("param1", queueName)
>               .parameter("param2", restApiEndpoint)
>               .add();
>       LOG.application.info("buildTemplatedRoute() created templated
> route: {}", route);
>
> When the service starts and calls the Camel 3.22.4 builder code, it fails
> and throws this:
>
> org.apache.camel.spring.boot.CamelSpringBootInitializationException:
> java.lang.IllegalArgumentException: Cannot find RouteTemplate with id
> template1
>         at
> org.apache.camel.spring.boot.CamelSpringBootApplicationListener.onApplicationEvent(CamelSpringBootApplicationListener.java:212)
> ~[camel-spring-boot-3.22.4.jar:3.22.4]
>         at
> org.apache.camel.spring.boot.CamelSpringBootApplicationListener.onApplicationEvent(CamelSpringBootApplicationListener.java:58)
> ~[camel-spring-boot-3.22.4.jar:3.22.4]
>         at
> org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:176)
> ~[spring-context-5.3.14.jar:5.3.14]
>         at
> org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:169)
> ~[spring-context-5.3.14.jar:5.3.14]
>         at
> org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:143)
> ~[spring-context-5.3.14.jar:5.3.14]
>         at
> org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:421)
> ~[spring-context-5.3.14.jar:5.3.14]
>         at
> org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:378)
> ~[spring-context-5.3.14.jar:5.3.14]
>         at
> org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:938)
> ~[spring-context-5.3.14.jar:5.3.14]
>         at
> org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:586)
> ~[spring-context-5.3.14.jar:5.3.14]
>         at
> org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:145)
> ~[spring-boot-2.6.2.jar:2.6.2]
>         at
> org.springframework.boot.SpringApplication.refresh(SpringApplication.java:730)
> ~[spring-boot-2.6.2.jar:2.6.2]
>         at
> org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:412)
> ~[spring-boot-2.6.2.jar:2.6.2]
>         at
> org.springframework.boot.SpringApplication.run(SpringApplication.java:302)
> ~[spring-boot-2.6.2.jar:2.6.2]
>         at
> org.springframework.boot.SpringApplication.run(SpringApplication.java:1301)
> ~[spring-boot-2.6.2.jar:2.6.2]
>         at
> org.springframework.boot.SpringApplication.run(SpringApplication.java:1290)
> ~[spring-boot-2.6.2.jar:2.6.2]
>         at
> ca.gc.esdc.interop.interfaces.cancelled_payments.payment.sps_f2r_ent.service.SpsMessageProcessorApplication.main(SpsMessageProcessorApplication.java:25)
> ~[classes/:na]
> Caused by: java.lang.IllegalArgumentException: Cannot find RouteTemplate
> with id ConsumerRouteDefaultTemplate
>         at
> org.apache.camel.impl.DefaultModel.addRouteFromTemplate(DefaultModel.java:419)
> ~[camel-core-engine-3.22.4.jar:3.22.4]
>         at
> org.apache.camel.impl.DefaultCamelContext.addRouteFromTemplate(DefaultCamelContext.java:502)
> ~[camel-core-engine-3.22.4.jar:3.22.4]
>         at
> org.apache.camel.builder.TemplatedRouteBuilder.add(TemplatedRouteBuilder.java:179)
> ~[camel-core-model-3.22.4.jar:3.22.4]
>         at
> ca.gc.esdc.interop.interfaces.cancelled_payments.payment.sps_f2r_ent.service.routes.SpsMessageProcessorRoute.buildTemplatedRoute(SpsMessageProcessorRoute.java:91)
> ~[classes/:na]
>         at
> ca.gc.esdc.interop.interfaces.cancelled_payments.payment.sps_f2r_ent.service.routes.SpsMessageProcessorRoute.defineRoutes(SpsMessageProcessorRoute.java:59)
> ~[classes/:na]
>         at
> ca.gc.esdc.interop.base.messageprocessor.routes.AbstractRoute.configure(AbstractRoute.java:38)
> ~[base-message-processor-1.3.0-DAN.jar:na]
>         at
> org.apache.camel.builder.RouteBuilder.checkInitialized(RouteBuilder.java:723)
> ~[camel-core-model-3.22.4.jar:3.22.4]
>         at
> org.apache.camel.builder.RouteBuilder.configureRoutes(RouteBuilder.java:668)
> ~[camel-core-model-3.22.4.jar:3.22.4]
>         at
> org.apache.camel.builder.RouteBuilder.addRoutesToCamelContext(RouteBuilder.java:600)
> ~[camel-core-model-3.22.4.jar:3.22.4]
>         at
> org.apache.camel.impl.engine.AbstractCamelContext.addRoutes(AbstractCamelContext.java:1212)
> ~[camel-base-engine-3.22.4.jar:3.22.4]
>         at
> org.apache.camel.main.RoutesConfigurer.addDiscoveredRoutes(RoutesConfigurer.java:247)
> ~[camel-main-3.22.4.jar:3.22.4]
>         at
> org.apache.camel.main.RoutesConfigurer.configureRoutes(RoutesConfigurer.java:222)
> ~[camel-main-3.22.4.jar:3.22.4]
>         at
> org.apache.camel.spring.boot.CamelSpringBootApplicationListener.onApplicationEvent(CamelSpringBootApplicationListener.java:106)
> ~[camel-spring-boot-3.22.4.jar:3.22.4]
>
> So it appears that there is some timing issue that makes this fail
> intermittently since the template cannot be found.
>
> One extra complication is that we have coded the route-template
> definitions in a dependent jar that is pulled into our spring-boot service
> by our maven build. So the code that actually builds and runs the route is
> in the service.
> We added this to our service main class in order to find the route in the
> dependent jar:
>
> @ComponentScan(basePackages = {
>       "package-for-the-dependent-jar",
>       "package-for-the-spring-boot-service"  // must be after the dep. jar
> package
>       })
>
> Wonder if what we see now with the builder is a known problem in Camel
> 3.22.4 ?
> Any comments/thoughts?
> Thanks,
> ...jvh



--
Claus Ibsen

Reply via email to