You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@camel.apache.org by "Claus Ibsen (Jira)" <ji...@apache.org> on 2023/01/14 17:53:00 UTC

[jira] [Commented] (CAMEL-18923) Cannot update a routeconfiguration with a routeloader

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

Claus Ibsen commented on CAMEL-18923:
-------------------------------------

Can you attach the reported as .zip instead of 7z

> Cannot update a routeconfiguration with a routeloader
> -----------------------------------------------------
>
>                 Key: CAMEL-18923
>                 URL: https://issues.apache.org/jira/browse/CAMEL-18923
>             Project: Camel
>          Issue Type: Bug
>          Components: came-core
>    Affects Versions: 3.20.1
>         Environment: openjdk version "11.0.17" 2022-10-18
> OpenJDK Runtime Environment Temurin-11.0.17+8 (build 11.0.17+8)
> OpenJDK 64-Bit Server VM Temurin-11.0.17+8 (build 11.0.17+8, mixed mode)
>            Reporter: Raymond
>            Priority: Minor
>         Attachments: routeloader-with-routeconfiguration.7z
>
>
> I load a routeConfiguration with the routeloader. This works from 3.20.0, but I can't get any info about it and cannot update the route after it is loaded.
> I use the following code:
>  
> {code:java}
> // 1. Start Camel
> context = new DefaultCamelContext();
> context.start();
> //2. Load route template
> context.addRoutes((RouteBuilder) new MyTemplate());
> //3. Create route template resource from string
> String content = "<templatedRoutes id=\"camel\" xmlns=\"http://camel.apache.org/schema/spring\">\n" +
>         "    <!-- create two routes from the template -->\n" +
>         "    <templatedRoute routeTemplateRef=\"myTemplate\">\n" +
>         "        <parameter name=\"name\" value=\"Manually Loaded Tempate\"/>\n" +
>         "        <parameter name=\"greeting\" value=\"Hello\"/>\n" +
>         "    </templatedRoute>\n" +
>         "</templatedRoutes>";
> Resource resource = ResourceHelper.fromString("in-memory.xml", content);
> //4. Load resource
> ExtendedCamelContext extendedCamelContext = context.adapt(ExtendedCamelContext.class);
> RoutesLoader loader = extendedCamelContext.getRoutesLoader();
> loader.loadRoutes(resource);
> //5. check the size of all routes
> LOG.info("RoutesSize = " + context.getRoutesSize());
> //6. Create route configuration resource from string
> content = "<routeConfiguration id=\"myRouteConfig\">\n" +
>         "\t<onException>\n" +
>         "\t   <exception>java.lang.Exception</exception>\n" +
>         "\t   <redeliveryPolicy maximumRedeliveries=\"0\" redeliveryDelay=\"5000\"/>\n" +
>         "\t   <setExchangePattern pattern=\"InOut\"/>\n" +
>         "\t</onException>\n" +
>         "</routeConfiguration>";
> resource = ResourceHelper.fromString("in-memory.xml", content);
> //7. Load resource
> loader.loadRoutes(resource);
> //8. Print something of hte status of the routeconfiguraton
> LOG.info("RoutesSize = " + context.getRoutesSize());
> LOG.info("RouteConfiguration Status = " + context.getRouteController().getRouteStatus("myRouteConfig"));
> Route route = context.getRoute("myRouteConfig");
> if(route != null){
>     LOG.info("RouteConfiguration Uptime = " + route.getUptimeMillis());
> }else{
>     LOG.info("RouteConfiguration is null");
> }
> //9. Update resource
> loader.updateRoutes(resource);
> route = context.getRoute("myRouteConfig");
> if(route != null){
>     LOG.info("2. RouteConfiguration Uptime = " + route.getUptimeMillis());
> }else{
>     LOG.info("2. RouteConfiguration is null");
> } {code}
> Log using Apache Camel 3.19.0
> {code:java}
> [INFO] Starting Camel ...
> 16:27:05.793 [org.apache.camel.example.MyApplication.main()] INFO  o.a.c.i.engine.AbstractCamelContext - Apache Camel 3.19.0 (camel-1) is starting
> 16:27:05.829 [org.apache.camel.example.MyApplication.main()] INFO  o.a.c.i.engine.AbstractCamelContext - Routes startup (started:0)
> 16:27:05.829 [org.apache.camel.example.MyApplication.main()] INFO  o.a.c.i.engine.AbstractCamelContext - Apache Camel 3.19.0 (camel-1) started in 429ms (build:216ms init:190ms start:23ms)
> 16:27:06.413 [org.apache.camel.example.MyApplication.main()] INFO  o.apache.camel.example.MyApplication - RoutesSize = 1
> 16:27:06.439 [org.apache.camel.example.MyApplication.main()] INFO  o.apache.camel.example.MyApplication - RoutesSize = 1
> 16:27:06.440 [org.apache.camel.example.MyApplication.main()] INFO  o.apache.camel.example.MyApplication - RouteConfiguration Status = null
> 16:27:06.440 [org.apache.camel.example.MyApplication.main()] INFO  o.apache.camel.example.MyApplication - RouteConfiguration is null
> 16:27:06.442 [org.apache.camel.example.MyApplication.main()] INFO  o.apache.camel.example.MyApplication - RouteConfiguration is null
> 16:27:07.423 [Camel (camel-1) thread #1 - timer://Manually Loaded Tempate] INFO  route2 - Hello Manually Loaded Tempate
> 16:27:10.413 [Camel (camel-1) thread #1 - timer://Manually Loaded Tempate] INFO  route2 - Hello Manually Loaded Tempate {code}
> Log using Apache Camel 3.20.0 (Same code)
>  
> {code:java}
> [INFO] Starting Camel ...
> 16:29:52.895 [org.apache.camel.example.MyApplication.main()] INFO  o.a.c.i.engine.AbstractCamelContext - Apache Camel 3.20.0 (camel-1) is starting
> 16:29:52.913 [org.apache.camel.example.MyApplication.main()] INFO  o.a.c.i.engine.AbstractCamelContext - Routes startup (started:0)
> 16:29:52.913 [org.apache.camel.example.MyApplication.main()] INFO  o.a.c.i.engine.AbstractCamelContext - Apache Camel 3.20.0 (camel-1) started in 416ms (build:250ms init:156ms start:10ms)
> 16:29:53.121 [org.apache.camel.example.MyApplication.main()] INFO  o.apache.camel.example.MyApplication - RoutesSize = 0
> 16:29:53.154 [org.apache.camel.example.MyApplication.main()] INFO  o.apache.camel.example.MyApplication - RoutesSize = 0
> 16:29:53.155 [org.apache.camel.example.MyApplication.main()] INFO  o.apache.camel.example.MyApplication - RouteConfiguration Status = null
> 16:29:53.157 [org.apache.camel.example.MyApplication.main()] INFO  o.apache.camel.example.MyApplication - RouteConfiguration is null
> [ERROR] *************************************
> [ERROR] Error occurred while running main from: org.apache.camel.example.MyApplication
> [ERROR]
> java.lang.reflect.InvocationTargetException
>     at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
>     at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
>     at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
>     at java.lang.reflect.Method.invoke (Method.java:566)
>     at org.apache.camel.maven.RunMojo$1.run (RunMojo.java:412)
>     at java.lang.Thread.run (Thread.java:829)
> Caused by: java.lang.IllegalArgumentException: Route configuration already exists with id: myRouteConfig
>     at org.apache.camel.impl.DefaultModel.addRouteConfiguration (DefaultModel.java:139)
>     at org.apache.camel.impl.DefaultCamelContext.addRouteConfiguration (DefaultCamelContext.java:311)
>     at org.apache.camel.dsl.xml.io.XmlRoutesBuilderLoader$1.addConfigurations (XmlRoutesBuilderLoader.java:92)
>     at java.util.Optional.ifPresent (Optional.java:183)
>     at org.apache.camel.dsl.xml.io.XmlRoutesBuilderLoader$1.configuration (XmlRoutesBuilderLoader.java:76)
>     at org.apache.camel.builder.RouteConfigurationBuilder.updateRouteConfigurationsToCamelContext (RouteConfigurationBuilder.java:88)
>     at org.apache.camel.impl.engine.DefaultRoutesLoader.updateRoutes (DefaultRoutesLoader.java:186)
>     at org.apache.camel.spi.RoutesLoader.updateRoutes (RoutesLoader.java:98)
>     at org.apache.camel.example.MyApplication.main (MyApplication.java:79)
>     at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
>     at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
>     at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
>     at java.lang.reflect.Method.invoke (Method.java:566)
>     at org.apache.camel.maven.RunMojo$1.run (RunMojo.java:412)
>     at java.lang.Thread.run (Thread.java:829) {code}
> I added an example in the attachement.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)