Details
Description
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:
// 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"); }
Log using Apache Camel 3.19.0
[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
Log using Apache Camel 3.20.0 (Same code)
[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)
I added an example in the attachement.