- Queue-based task distribution
- Multiple worker instances
- State-driven workflows
- Cron-triggered maintenance
Use cases
- Image processing pipelines
- Email batch sending
- Data import/export
- Report generation
- Cleanup and maintenance tasks
Architecture
This example processes messages through a pipeline:- HTTP endpoint: Receives messages and enqueues them
- Queue worker: Processes messages in the background
- Cron job: Handles periodic cleanup
Step 1: Create the message endpoint
Createsteps/send-message.step.ts to receive and enqueue messages:
steps/send-message.step.ts
Step 2: Create the background worker
Createsteps/process-message.step.ts to process messages:
steps/process-message.step.ts
Worker features
- Error handling: Catches errors and updates state
- Retry support: Throwing errors triggers queue retry mechanism
- Priority processing: Adjusts work based on priority
- State tracking: Updates message status throughout lifecycle
Step 3: Add periodic cleanup
Createsteps/cleanup-messages.step.ts for maintenance:
steps/cleanup-messages.step.ts
Advanced: Multiple workers with state trigger
Createsteps/notify-completion.step.ts to react to state changes:
steps/notify-completion.step.ts
Testing the worker
Send a message
Monitor processing
Check the iii Console to see:- Message received by HTTP endpoint
- Message enqueued to
message.senttopic - Background worker processing the message
- State updated with processing results
- Notification sent via state trigger
Configuration: Queue strategies
Configure queue behavior iniii-config.yaml:
iii-config.yaml
Queue options
- max_retries: Number of retry attempts for failed messages
- retry_delay: Delay between retries in milliseconds
- concurrency: Number of concurrent workers
- dead_letter_queue: Queue for permanently failed messages
Scaling workers
The iii engine automatically distributes work across multiple instances. To scale:- Load distribution
- High availability
- Fault tolerance
What you learned
Queue triggers
Process messages asynchronously with queues
Error handling
Handle failures and implement retry logic
State triggers
React to state changes automatically
Cron jobs
Schedule periodic maintenance tasks
Next steps
ChessArena example
See a full production app with background workers
Workflows guide
Build complex multi-step workflows