Orchestrators: Declarative Workflow Automation

Learn how to build predefined and dynamic workflows using Orchestrator

While connecting handlers with channels works great for linear workflows, and Sagas excel at stateful processes, Orchestrator is perfect when you need predefined workflows where the workflow definition is separate from the individual steps.

When Do You Need Orchestrator?

Use Orchestrator when you want to:

🎯 Separate workflow from steps: Define the flow independently of step implementation 🔄 Reuse steps: Use the same steps in different workflows ⚡ Build dynamic workflows: Construct workflows programmatically based on business rules 🧪 Easy testing: Test workflows and steps independently 📋 Predefined processes: Execute well-defined business processes consistently

Examples:

  • Image processing pipeline (resize → watermark → optimize → upload)

  • Document approval workflow (validate → review → approve → notify)

  • Order fulfillment process (verify → payment → shipping → tracking)

  • Customer onboarding (registration → verification → welcome → setup)

Think of Orchestrator as: A conductor that knows the entire symphony (workflow) and tells each musician (step) when to play, while the musicians focus only on their part.

Prerequisites: Understanding of message handlers and channels will help you get the most out of Orchestrator.

Creating Your First Orchestrator

An Orchestrator defines a workflow as a sequence of steps (channel names) and implements those steps as internal handlers.

Step 1: Define the Workflow

Key parts:

  • #[Orchestrator] - Tells Ecotone this method defines a workflow

  • inputChannelName - Channel that triggers this workflow

  • Return array - List of steps (channel names) to execute in order

Step 2: Implement the Steps

What happens when you trigger the workflow:

  1. Message sent to process.image channel

  2. Orchestrator returns ["resize.image", "add.watermark", "optimize.image", "upload.image"]

  3. Each step executes in sequence, passing data to the next step

  4. Final result is returned

Data Enrichment with Headers

Sometimes you need to add metadata or context without changing the main payload. Use changingHeaders: true for this:

Enriching with Additional Data

Benefits of header enrichment:

  • Keep original payload unchanged

  • Add context data for downstream steps

  • Maintain clean separation of concerns

Executing Orchestrators

There are several ways to trigger orchestrator workflows:

Method 1: Command Handler with Output Channel

Flow:

  1. UploadImageCommand sent to command handler

  2. Handler processes upload and returns ImageData

  3. Result automatically sent to process.image channel

  4. Orchestrator workflow begins

Method 2: From Event Handlers (Business Workflows)

Flow:

  1. OrderPlaced event occurs

  2. Event handler processes it and sends result to process.order

  3. Orchestrator workflow begins automatically

Method 3: Business Interface Triggering Business Workflow

Business Interface is simple interface where Ecotone delivers implementation. This way we can easily create and entrypoint with interface that is part of our application level code and execute the workflow:

Usage in your application:

Method 4: Custom Orchestrator Gateway

For dynamic workflows where you want to pass the steps programmatically:

Gateway benefits:

  • Dynamic workflow construction

  • Runtime step determination

  • Easy integration with web controllers

  • Flexible business rule application

Asynchronous Orchestration

Make your workflows asynchronous for better performance and scalability:

Asynchronous Orchestrator

Mixed Synchronous/Asynchronous Steps

Advanced Features

Dynamic Workflow Building

The power of Orchestrator shines when you build workflows dynamically based on business rules:

Conditional Step Execution

Steps can return null to end the workflow early:

Nested Orchestrators

Orchestrators can call other orchestrators as steps:

Testing Orchestrators

Testing orchestrators is straightforward with Ecotone Lite. You can test the entire workflow, individual steps, or specific scenarios.

Testing Individual Steps

Testing Data Enrichment

Testing Asynchronous Orchestrators

Testing Orchestrator Gateways

Key Benefits of Orchestrator

🎯 Separation of Concerns

  • Workflow definition is separate from step implementation

  • Easy to understand the entire process at a glance

  • Steps can be reused across different workflows

🔄 Reusability

  • Same steps can be used in multiple workflows

  • Build libraries of reusable business operations

  • Mix and match steps for different scenarios

Dynamic Workflows

  • Build workflows programmatically based on business rules

  • Adapt to different customer types, regions, or conditions

  • Runtime workflow construction

🧪 Testability

  • Test entire workflows end-to-end

  • Test individual steps in isolation

  • Easy mocking and stubbing of dependencies

📈 Scalability

  • Asynchronous execution support

  • Individual steps can be scaled independently

  • Easy to add new steps without changing existing code

🔍 Observability

  • Clear workflow execution path

  • Easy to monitor and debug

  • Step-by-step execution tracking

Summary

Orchestrator is perfect for building predefined workflows where you want to:

  • 🎯 Separate workflow definition from step implementation

  • 🔄 Reuse steps across different workflows

  • Build dynamic workflows based on business rules

  • 🧪 Test workflows and steps independently

  • 📋 Execute consistent, repeatable business processes

The power of Orchestrator lies in its ability to make complex business workflows simple to define, easy to test, and flexible to modify. Whether you're processing orders, onboarding customers, or handling document workflows, Orchestrator provides the structure and flexibility you need to build robust, maintainable business processes.

Last updated

Was this helpful?