davsclaus opened a new pull request, #30883:
URL: https://github.com/apache/camel/pull/30883

   CAMEL-17129: camel-core-model - saga and transacted keep the order of the 
steps
   
   [CAMEL-17129](https://issues.apache.org/jira/browse/CAMEL-17129)
   
   ## Problem
   
   A `saga` or `transacted` wraps the entire route: when the route is prepared, 
`RouteDefinitionHelper` moves the regular
   steps of the route into it. It did so with `getOutputs().addAll(0, lower)`, 
where `lower` holds the steps both before
   and after the `saga`/`transacted`. In the XML and YAML DSL a 
`saga`/`transacted` can have nested steps of its own,
   followed by sibling steps, and then the sibling steps were put in front of 
the nested steps:
   
   ```yaml
   - from:
       uri: direct:start
       steps:
         - saga:
             steps:
               - to: direct:something
         - to: mock:result
   ```
   
   ran `mock:result` before `direct:something`. The same happened in the Java 
DSL with `.transacted() ... .end()` followed
   by more steps. The YAML `SagaTest` even asserted this order, with a link to 
the ticket.
   
   ## Change
   
   The steps of the route keep the order they are written in: the steps before 
the `saga`/`transacted`, its nested steps,
   then the steps after it, all inside the `saga`/`transacted` (as in the Java 
DSL, where everything after `.transacted()`
   is inside the transaction, and the steps before it were already moved into 
it).
   
   `initSagas` and `initTransacted` are merged into one method that walks the 
route outputs as written and expands the
   nested steps of the `saga`/`transacted` in place. The nesting is unchanged: 
the `saga` is inside the `transacted`. When
   a route has both as top-level steps, the nested steps of the `transacted` 
are now part of the saga as well (before they
   ran after the saga, outside of it).
   
   The Java DSL forms `.saga()` / `.transacted()` (steps after it are its 
children), and `<transacted/>` / `- transacted: {}`
   without nested steps, give the same model as before.
   
   ## Tests
   
   - `core/camel-core`: new `SagaTransactedStepOrderTest` (Java DSL 
saga/transacted, Java DSL with `.end()`, XML saga and
     transacted with nested steps followed by siblings, XML without nested 
steps, XML with both saga and transacted in
     either order). Fails on main: 5 of 8 (`Expected: <x-a-b-c> but was: 
<x-a-c>`); the plain Java DSL and the
     no-nested-steps cases pass on main and with the fix, so their model is 
unchanged.
   - `dsl/camel-yaml-dsl`: `TransactedTest#transactedKeepsTheStepOrder` 
(runtime order) and `SagaTest` now asserts the
     written order. Both fail on main.
   - Module tests: `camel-core-model` 11, `camel-core` 9915 (0 failures, 44 
skipped), `camel-yaml-dsl` 531, all pass.
   
   ## Upgrade notes
   
   Entry in the 4.24 upgrade guide: XML/YAML routes with a `saga`/`transacted` 
that has nested steps followed by sibling
   steps now run the steps in the written order. The Saga EIP and Transactional 
Client pages say so too.
   
   _Claude Code on behalf of davsclaus_
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)
   


-- 
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