[ 
https://issues.apache.org/jira/browse/CAMEL-15555?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17358446#comment-17358446
 ] 

Claus Ibsen commented on CAMEL-15555:
-------------------------------------

With CDI you can use observers to trigger after camel is started then you can 
use a bean to add new routes from templates such as

{code}
@ApplicationScoped
public class MyRouteCreatorBean {

    private static final Logger LOG = 
LoggerFactory.getLogger(MyRouteCreatorBean.class);

    @Inject
    CamelContext context;

    public void setupRoutes(@Observes CamelEvent.CamelContextStartedEvent 
startup) throws Exception {
        LOG.info("Creating routes from templates");

        Map<String, Object> parameters = new HashMap<>();
        parameters.put("start", "foo");
        parameters.put("append", "A");
        context.addRouteFromTemplate("foo", "myTemplate", parameters);
        parameters.clear();
        parameters.put("start", "bar");
        parameters.put("append", "B");
        context.addRouteFromTemplate("bar", "myTemplate", parameters);
    }
}
{code}

> RouteTemplates creating in CDI are configured out-of-order
> ----------------------------------------------------------
>
>                 Key: CAMEL-15555
>                 URL: https://issues.apache.org/jira/browse/CAMEL-15555
>             Project: Camel
>          Issue Type: Bug
>          Components: camel-cdi
>    Affects Versions: 3.5.0
>            Reporter: Paul Campbell
>            Priority: Minor
>             Fix For: 3.x
>
>
> When:
>  * using Camel with CDI
>  * having routes defined in multiple beansĀ 
>  * one bean defines the route template
>  * another bean attempts to create a route from that template
> I would expect that the route templates are configured before any routes that 
> build from them.
> What happens is non-deterministic based on the order the RoutesBuilder 
> instances are provided by the CDI runtime. In a good case, the template bean 
> is processed first and all is as-expected. However, when the template bean is 
> provided after any bean that attempts to build from it we get the error:
> {{Caused by: java.lang.IllegalArgumentException: Cannot find RouteTemplate 
> with id ListProcess}}
> {{ at 
> org.apache.camel.quarkus.core.BaseModel.addRouteFromTemplate(BaseModel.java:167)}}
> {{ at 
> org.apache.camel.quarkus.core.FastCamelContext.addRouteFromTemplate(FastCamelContext.java:188)}}
> {{ at 
> org.apache.camel.builder.TemplatedRouteBuilder.add(TemplatedRouteBuilder.java:104)}}
> Attempted a workaround by annotating the template bean with @Priority(1), 
> however this had no effect.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to