SEQUENCE Step
The SEQUENCE step allows you to group multiple steps together and, more importantly, define how the flow should handle errors within that group. It is the primary tool for implementing Try/Catch/Finally logic.
Properties
| Property | Type | Description |
|---|---|---|
type | string | Must be sequence. |
exitOn | string | Strategy for when to stop the sequence: FAILURE, SUCCESS, or DONE. |
steps | array | The nested steps to execute within this sequence. |
Exit Strategies (exitOn)
The exitOn property determines the "success" or "failure" behavior of the entire group.
1. exitOn: FAILURE (The "Standard" Block)
- Behavior: Executes steps one by one. If any step fails (returns an error), the sequence stops immediately and returns that error to the parent.
- Use Case: Default grouping for a set of related operations that depend on each other.
2. exitOn: SUCCESS (The "Try" Block)
- Behavior: Executes steps until one succeeds. Once a step is successful, the sequence stops and returns successfully.
- Use Case: Used as a container for Try/Catch patterns or when you have multiple ways to achieve a goal and only need one to work.
3. exitOn: DONE (The "Catch/Finally" Block)
- Behavior: Executes all steps regardless of whether they succeed or fail. Individual errors within the sequence are suppressed.
- Use Case: Cleanup logic, logging failures, or "Catch" blocks where you want to handle an error and then continue the main flow.
Pattern: Try / Catch
To implement a classic Try/Catch in Joynare Nexus, use a nested structure:
yaml
- name: "SafeDivision"
type: "sequence"
exitOn: "SUCCESS" # Once either Try or Catch finishes successfully, we are done
steps:
- name: "TryBlock"
type: "sequence"
exitOn: "FAILURE" # Stop at the first error
steps:
- type: "invoke"
service: "system.math:Divide"
input: { a: "${a}", b: "${b}" }
output: { result: "result" }
- type: "map"
set: { status: "OK" }
- name: "CatchBlock"
type: "sequence"
exitOn: "DONE" # Always run if TryBlock failed
steps:
- type: "map"
set:
status: "ERROR"
result: 0Data Flow Scenario: Successful Execution
Initial Pipeline:
json
{ "a": 10, "b": 2 }Resulting Pipeline:
json
{ "a": 10, "b": 2, "result": 5, "status": "OK" }Data Flow Scenario: Error Handled
Initial Pipeline:
json
{ "a": 10, "b": 0 }Resulting Pipeline:
json
{ "a": 10, "b": 0, "result": 0, "status": "ERROR" }(Note: The 'Divide' service failed, triggering the CatchBlock which sanitized the output)
Tips
- Meaningful Names: Always give your sequences names like
MainLogic,Cleanup, orErrorHandlerto make the execution logs easy to read. - Implicit Root: The top-level
stepsof a Flow Service act like a sequence withexitOn: FAILURE. - Nesting: You can nest sequences as deeply as needed to create complex error-recovery logic.
