Adriano Machado created CAMEL-27754:
---------------------------------------

             Summary: camel-core - top-level onCompletion in YAML and Spring 
XML fires once per route instead of once per exchange
                 Key: CAMEL-27754
                 URL: https://issues.apache.org/jira/browse/CAMEL-27754
             Project: Camel
          Issue Type: Bug
          Components: camel-core
            Reporter: Adriano Machado


Found while reviewing 
[CAMEL\-25420|https://issues.apache.org/jira/browse/CAMEL-25420] 
\(apache/camel#31060\).

The Java DSL {{RoutesDefinition.onCompletion\(\)}} \(a context\-scoped 
{{onCompletion}} in a {{RouteBuilder}}\) sets {{routeScoped=false}}, so the 
{{onCompletion}} fires once per exchange, for the route that consumed it. Two 
other DSLs add the same top\-level {{onCompletion}} without that, and it keeps 
the model default {{routeScoped=true}}:

* *YAML*: a top\-level {{\- onCompletion:}} is added with 
{{getRouteCollection\(\).getOnCompletions\(\).add\(...\)}} in 
{{YamlRoutesBuilderLoader}}.
* *Spring XML*: {{<camelContext><onCompletion>}} is bound by JAXB and collected 
in {{AbstractCamelContextFactoryBean}} \({{getOnCompletions\(\)}}\).

As a result the {{onCompletion}} fires once for each route of the exchange. 
Reproduced on {{main}} \(4.24.0\-SNAPSHOT, with the CAMEL\-25420 fix applied\): 
routes {{direct:start \-> direct:sub \-> mock:result}} with a top\-level 
{{onCompletion}} that sends to {{mock:on\-completion}} deliver *2* messages to 
{{mock:on\-completion}} for one exchange, in both YAML and Spring XML.

YAML reproducer:

{code}
- onCompletion:
    steps:
      - to: "mock:on-completion"
- from:
    uri: "direct:start"
    steps:
      - to: "direct:sub"
- from:
    uri: "direct:sub"
    steps:
      - to: "mock:result"
{code}

The XML IO DSL has no top\-level {{onCompletion}}, so it is not affected. A 
possible fix is to set {{routeScoped=false}} where these context\-scoped 
definitions are collected, as CAMEL\-25420 does for route configurations in 
{{RouteDefinitionHelper.getRouteConfigurationDefinitionConsumer\(\)}}. It 
changes behavior for users who relied on the per\-route firing, so it needs an 
upgrade\-guide entry.

_Claude Code on behalf of Adriano Machado \(@ammachado\)_

_This was generated by an AI agent and may contain inaccuracies. Please verify 
before relying on it._





--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to