This is a project for demonstrating Temporal with the Rust SDK.
It implements a money transfer workflow that orchestrates withdrawing from a source account and depositing into a target account, with configurable retry policies and non-retryable error handling.
Based on the Go money transfer template.
src/
├── shared.rs # PaymentDetails struct and task queue constant
├── workflow.rs # MoneyTransferWorkflow definition with retry policy
├── activity.rs # Withdraw, deposit, and refund activities
├── banking_client.rs # Mock banking service with in-memory accounts
├── worker/main.rs # Worker binary — registers workflows and activities
└── start/main.rs # Starter binary — kicks off a workflow execution
temporal-test-harness/ # Testing utility for running workflows without a server
tests/
├── activity_tests.rs # Unit tests for banking activities
└── workflow_replay_tests.rs # Workflow integration tests using mock history
- Rust (edition 2024)
- A running Temporal Server
Make sure Temporal Server is running first. The quickest way is with the Temporal CLI:
temporal server start-devOr with Docker Compose:
git clone https://github.com/temporalio/docker-compose.git
cd docker-compose
docker-compose upIn another terminal instance, clone this repo:
git clone <repo-url>
cd temporal-rs-tutorialcargo run --bin startObserve that Temporal Web (http://localhost:8233) reflects the workflow, but it is still in "Running" status. This is because there is no Worker yet listening to the TRANSFER_MONEY_TASK_QUEUE task queue to process this work.
In another terminal instance, run the worker. This worker hosts both the Workflow and Activity implementations.
cargo run --bin workerNow you can see the workflow run to completion.
The project includes unit tests for activities and workflow replay tests that run without a Temporal Server. This is a bit of a prototype on my part as I couldn't see any obvious way to do this with the current rust sdk alpha:
cargo testRun specific test suites:
cargo test --test activity_tests
cargo test --test workflow_replay_testsThe MoneyTransferWorkflow executes two activities in sequence:
- Withdraw — pulls funds from the source account
- Deposit — deposits funds into the target account
Each activity is configured with a retry policy:
- Initial interval: 1 second
- Backoff coefficient: 2x
- Maximum interval: 5 seconds
- Maximum attempts: 5
- Non-retryable errors:
InvalidAccountError,InsufficientFundsError
The workflow uses rust_decimal::Decimal for precise monetary calculations.