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.
Enterprise Feature: Orchestrator is part of Ecotone's Enterprise features.
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 workflowinputChannelName- Channel that triggers this workflowReturn array - List of steps (channel names) to execute in order
Step 2: Implement the Steps
What happens when you trigger the workflow:
Message sent to
process.imagechannelOrchestrator returns
["resize.image", "add.watermark", "optimize.image", "upload.image"]Each step executes in sequence, passing data to the next step
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:
UploadImageCommandsent to command handlerHandler processes upload and returns
ImageDataResult automatically sent to
process.imagechannelOrchestrator workflow begins
Method 2: From Event Handlers (Business Workflows)
Flow:
OrderPlacedevent occursEvent handler processes it and sends result to
process.orderOrchestrator 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
Key insight: Orchestrator shines when you know the types of workflows you need but want flexibility in how they're constructed and executed. It's the perfect balance between structure and flexibility.
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?