Quickstart
Configure your local development environment to get started developing with Temporal using the Rust SDK.
Install Rust
Make sure you have Rust installed on your system. You can download and install Rust from rustup.rs.
After installation, verify it's working by checking the version. You'll also need Cargo, which is Rust's package manager and comes bundled with Rust.
rustc --version
Create a Project
Now that you have Rust and Cargo installed, create a new Rust project to manage your dependencies.
mkdir temporal-rust-project
cd temporal-rust-project
cargo init --name temporal-hello-world
Add Temporal Rust SDK Dependencies
Now add the Temporal SDK dependencies to your project's Cargo.toml file.
The core dependencies you'll need are:
temporalio- The Rust SDK for Temporaltemporalio-client- Client library to start workflows and interact with the Temporal servicetemporalio-macros- Macros for defining workflows and activitiestokio- Async runtime required by the SDKserde- For serialization/deserialization
Next, you'll configure a local Temporal Service for development.
[package]
name = "temporal-hello-world"
version = "0.1.0"
edition = "2021"
[dependencies]
tokio = { version = "1", features = ["full"] }
temporalio = "0.2"
temporalio-client = "0.2"
temporalio-macros = "0.2"
serde = { version = "1", features = ["derive"] }
serde_json = "1"
Install Temporal CLI and start the development server
The fastest way to get a development version of the Temporal Service running on your local machine is to use Temporal CLI.
Choose your operating system to install Temporal CLI:
- macOS
- Windows
- Linux
brew install temporal
Download the Temporal CLI archive for your architecture:
Extract it and add temporal.exe to your PATH.
Download the Temporal CLI for your architecture:
Extract the archive and move the temporal binary into your PATH:
sudo mv temporal /usr/local/bin
Start the development server
Once you've installed Temporal CLI and added it to your PATH, open a new Terminal window and run the following command.
This command starts a local Temporal Service. It starts the Web UI, creates the default Namespace, and uses an in-memory database.
The Temporal Service will be available on localhost:7233. The Temporal Web UI will be available at http://localhost:8233.
Leave the local Temporal Service running as you work through tutorials and other projects. You can stop the Temporal Service at any time by pressing CTRL+C.
After installing, open a new Terminal. Keep this running in the background:
temporal server start-dev
Change the Web UI port
The Temporal Web UI may be on a different port in some examples or tutorials. To change the port for the Web UI, use the --ui-port option when starting the server:
temporal server start-dev --ui-port 8080
The Temporal Web UI will now be available at http://localhost:8080.
Run Hello World: Test Your Installation
Now let's verify your setup is working by creating and running a complete Temporal application with both a Workflow and Activity.
This test will confirm that:
- The Temporal Rust SDK is properly installed
- Your local Temporal Service is running
- You can successfully create and execute Workflows and Activities
- The communication between components is functioning correctly
1. Define Your Activity
Create an activities.rs file with the Activity definition:
use temporalio_sdk::activities::{ActivityContext, ActivityError};
use temporalio_macros::activities;
#[activities]
impl GreetingActivities {
#[activity]
pub async fn greet(_ctx: ActivityContext, name: String) -> Result<String, ActivityError> {
Ok(format!("Hello, {}!", name))
}
}
pub struct GreetingActivities;
2. Define Your Workflow
Create a workflows.rs file with the Workflow definition:
use std::time::Duration;
use temporalio_sdk::{
activities::ActivityOptions, workflow::*, ActivityResult, WorkflowResult,
};
use temporalio_macros::{workflow, workflow_methods};
#[workflow]
pub struct GreetingWorkflow {
name: String,
}
#[workflow_methods]
impl GreetingWorkflow {
#[init]
fn new(_ctx: &WorkflowContextView, name: String) -> Self {
Self { name }
}
#[run]
async fn run(ctx: &mut WorkflowContext<Self>) -> WorkflowResult<String> {
let name = ctx.state(|s| s.name.clone());
let greeting = ctx.activity(
GreetingActivities::greet,
name,
ActivityOptions {
start_to_close_timeout: Some(Duration::from_secs(10)),
..Default::default()
}
).await?;
Ok(greeting)
}
}
3. Set Up and Run a Worker
Create your main main.rs file:
use temporalio_client::{Client, ClientOptions, Connection, envconfig::LoadClientConfigProfileOptions};
use temporalio_sdk::{Worker, WorkerOptions};
use temporalio_sdk_core::{CoreRuntime, RuntimeOptions};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Create the core runtime
let runtime = CoreRuntime::new_assume_tokio(RuntimeOptions::builder().build()?)?;
// Load client configuration from environment or config file
let (conn_options, client_options) = ClientOptions::load_from_config(
LoadClientConfigProfileOptions::default()
)?;
let connection = Connection::connect(conn_options).await?;
let client = Client::new(connection, client_options);
// Create worker options
let worker_options = WorkerOptions::new("my-task-queue")
.register_activities(GreetingActivities)
.register_workflow::<GreetingWorkflow>()
.build();
// Run the worker
Worker::new(&runtime, client, worker_options)?.run().await?;
Ok(())
}
4. Start a Workflow
You can now start a workflow execution using the client. Create a starter script or use the Temporal CLI to begin your first workflow execution.
Next Steps
Now that you have the basics working, explore the following resources to build more sophisticated applications:
- Develop a Workflow - Learn how to write complex workflow logic
- Develop an Activity - Understand activity patterns and best practices
- Worker Processes - Configure and scale workers
- Using the Temporal Client - Start workflows and interact with the Temporal Service