gnodet-bot commented on code in PR #30224:
URL: https://github.com/apache/camel/pull/30224#discussion_r4591097351
##########
core/camel-core-reifier/src/main/java/org/apache/camel/reifier/SendReifier.java:
##########
@@ -67,4 +85,83 @@ public Endpoint resolveEndpoint() {
return answer;
}
+ /**
+ * A to resolves its endpoint once, when the route is created, so a Simple
expression in the path of its uri is not
+ * evaluated for each message: every message goes to the one endpoint
named by the text of the expression. Logs a
+ * WARN that says to use toD, unless the component evaluates its path
itself. It is the rule camel validate checks
+ * the routes with: only the path is looked at, not the options after the
?.
+ */
+ private void warnIfExpressionInUri() {
+ if (definition.getEndpoint() != null) {
+ // an endpoint given as an object, not a uri written in the route
+ return;
+ }
+ try {
+ String uri = definition.getEndpointUri();
+ if (uri == null) {
+ return;
+ }
+ String resolved = uri;
+ if (uri.contains(PropertiesComponent.PREFIX_TOKEN)) {
+ resolved =
EndpointHelper.resolveEndpointUriPropertyPlaceholders(camelContext, uri);
+ }
+ String expression = expressionInPath(resolved);
+ if (expression != null &&
!pathTakesExpression(resolved.substring(0, resolved.indexOf(':')))) {
+ LOG.warn("The to in route {} sends to {}, whose uri has the
expression {}: a to resolves its endpoint"
+ + " once, when the route is created, so the
expression is not evaluated for each message, and"
+ + " every message goes to the endpoint named by its
text. Use toD to compute the endpoint uri"
+ + " for each message.",
+ route.getRouteId(), URISupport.sanitizeUri(uri),
expression);
+ }
+ } catch (Exception e) {
+ LOG.debug("Cannot check the uri of {} for an expression. This
exception is ignored.", definition, e);
+ }
+ }
+
+ /**
+ * The first Simple expression in the path of the uri (what comes before
its options), or null when there is none.
Review Comment:
💡 The Javadoc for `expressionInPath` says *"The path of the language
component is a script"* but the method itself doesn't handle the `language`
component — that exclusion is done by the `SCRIPT_PATH` check in
`warnIfExpressionInUri()` before this method is called. The Javadoc slightly
misrepresents the responsibility boundary. Consider: *"The caller excludes the
`language` component before calling this method."*
##########
core/camel-core-engine/src/main/docs/modules/eips/pages/to-eip.adoc:
##########
@@ -145,6 +145,13 @@ is capable of computing a dynamic URI using
an xref:manual::expression.adoc[Expression], such as
the xref:components:eips:toD-eip.adoc[toD] or
xref:components:eips:recipientList-eip.adoc[Recipient List] EIP pattern.
+The route still starts: the `to` sends every message to one endpoint, named by
the text of the expression.
+Camel logs a WARN for such a `to` when it creates the route, and the WARN says
to use `toD`.
+Only the endpoint path is checked, not the options after the `?`. A component
that evaluates the expressions
+in its path for each message is left alone, such as
xref:ROOT:language-component.adoc[Language] and
+xref:ROOT:sql-stored-component.adoc[SQL Stored Procedure], as are the
`:#${...}` parameters of the
+xref:ROOT:sql-component.adoc[SQL] component.
Review Comment:
💡 The exclusion text names `Language` and `SQL Stored Procedure` explicitly,
but the actual gating mechanism is the `supportSimpleExpression` metadata
attribute on the path option. As more components adopt the flag (file,
micrometer, opentelemetry-metrics, hibernate already have it), this list will
go stale. Consider describing the mechanism instead of the components:
```suggestion
Only the endpoint path is checked, not the options after the `?`. A
component whose path option
is marked `supportSimpleExpression` in its metadata is left alone, because
it evaluates the
expressions for each message — as do
xref:ROOT:language-component.adoc[Language],
xref:ROOT:sql-stored-component.adoc[SQL Stored Procedure], and the
`:#${...}` parameters of the
xref:ROOT:sql-component.adoc[SQL] component.
```
--
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]