davsclaus commented on a change in pull request #7091:
URL: https://github.com/apache/camel/pull/7091#discussion_r818349821



##########
File path: 
core/camel-core-engine/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
##########
@@ -975,6 +991,32 @@ protected synchronized boolean removeRoute(String routeId, 
LoggingLevel loggingL
         return removed;
     }
 
+    /**
+     * Indicates whether the route should be included according to the 
precondition.
+     *
+     * @param  definition the definition of the route to check.
+     * @return            {@code true} if the route should be included, {@code 
false} otherwise.
+     */
+    private boolean includedRoute(RouteDefinition definition) {
+        final String precondition = definition.getPrecondition();
+        if (precondition == null) {
+            LOG.debug("No precondition found, the route is included by 
default");

Review comment:
       I think trace level is fine here, as otherwise debug is a bit spammed as 
99,9% of routes are included

##########
File path: docs/user-manual/modules/ROOT/pages/routes.adoc
##########
@@ -54,6 +54,44 @@ rb -> rb.from("kafka:cheese").to("jms:queue:foo");
 There is a bit more to this as the lambda route must be coded in a Java method 
that returns an instance of `LambdaRouteBuilder`.
 See more at the xref:lambda-route-builder.adoc[LambdaRouteBuilder] 
documentation.
 
+== Route Precondition
+
+The routes can be included or not according to the result of a test expressed 
in simple language that is evaluated only once during the initialization phase.
+
+In the next example, the route is only included if the parameter `format` has 
been set to `xml`.
+
+[source,java]
+----
+from("direct:in").precondition("'{{format}}' == 'xml'")
+   .unmarshal().jaxb()
+   .to("direct:out");
+----
+
+And the same example using XML DSL:
+
+[source,xml]
+----
+<route precondition="'{{format}}' == 'xml'">
+  <from uri="direct:in"/>
+  <unmarshal><jaxb/></unmarshal>
+  <to uri="direct:out"/>
+</route>
+----
+
+And in YAML DS:

Review comment:
       DSL

##########
File path: 
core/camel-core-model/src/main/java/org/apache/camel/model/RouteDefinition.java
##########
@@ -456,6 +457,18 @@ public RouteDefinition autoStartup(boolean autoStartup) {
         return this;
     }
 
+    /**
+     * Sets the expression of the precondition in simple language to evaluate 
to determine if this route should be

Review comment:
       I think you should say predicate instead of expression - also further 
below




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to