Restate Rust SDK
Restate is a system for easily building resilient applications using distributed durable async/await. This repository contains the Restate SDK for writing services using Rust.
Community
- π€οΈ Join our online community for help, sharing feedback and talking to the community.
- π Check out our documentation to get quickly started!
- π£ Follow us on Twitter for staying up to date.
- π Create a GitHub issue for requesting a new feature or reporting a problem.
- π Visit our GitHub org for exploring other repositories.
Using the SDK
Add Restate and Tokio as dependencies:
[]
= "0.8"
= { = "1", = ["full"] }
Then you're ready to develop your Restate service using Rust:
use *;
;
async
Calling services through ingress
The impl-block service macros also generate a typed ingress client for each service. Enable the
reqwest-client feature to use the SDK's built-in HTTP transport:
[]
= { = "0.11", = ["reqwest-client"] }
ReqwestClient is an alias for the transport-neutral Client<reqwest::Client>. Connect it to a
Restate ingress base URI, then wrap it in the generated <Service>IngressClient:
use ReqwestClient;
let client = connect.unwrap;
let greeter = from_client;
// Wait for the invocation to complete and decode its typed result.
let response = greeter
.greet
.idempotency_key
.call
.await
.unwrap;
let invocation = response.invocation_handle;
assert_eq!;
println!;
// Enqueue an invocation without waiting for its result.
let response = greeter
.greet
.send
.await
.unwrap;
println!;
Generated object and workflow ingress clients additionally take their key in from_client. The
generic Client<E> and generated clients are available without reqwest-client; implement
RequestExecutor to use another buffered HTTP transport.
Connecting through a Restate Cloud tunnel
The optional Unix-only in-process tunnel lets a service connect outbound to Restate Cloud, so the
service does not need to expose an inbound HTTP port. Enable the tunnel feature:
[]
= { = "0.11", = ["tunnel"] }
= { = "1", = ["full"] }
When default features are disabled, select a crypto provider explicitly by adding either
rust_crypto or aws_lc_rs alongside tunnel. If both are enabled, rust_crypto is selected
deterministically.
The Restate operator injects the discovery and authentication settings, so an operator-managed deployment needs no application-side tunnel configuration:
use *;
async
See the complete tunnel example.
Running on Lambda
The Restate Rust SDK supports running services on AWS Lambda using Lambda Function URLs. This allows you to deploy your Restate services as serverless functions.
Setup
First, enable the lambda feature in your Cargo.toml:
[]
= { = "0.8", = ["lambda"] }
= { = "1", = ["full"] }
Basic Lambda Service
Here's how to create a simple Lambda service:
use *;
;
async
Deployment
-
Install
cargo-lambdacargo install cargo-lambda -
Build your Lambda function:
-
Create a Lambda function with the following configuration:
- Runtime: Amazon Linux 2023
- Architecture: arm64
-
Upload your
zipfile to the Lambda function.
Logging
The SDK uses tokio's tracing crate to generate logs.
Just configure it as usual through tracing_subscriber to get your logs.
Testing
The SDK uses Testcontainers to support integration testing using a Docker-deployed restate server.
The restate-sdk-testcontainers crate provides a framework for initializing the test environment, and an integration test example in testcontainers/tests/test_container.rs.
use ReqwestClient;
async
Versions
The Rust SDK is currently in active development, and might break across releases.
The compatibility with Restate is described in the following table:
| Restate Server\sdk-rust | 0.7 - 0.10 | 0.11 |
|---|---|---|
| 1.6 | β | β |
| 1.7 | β | β |
Some features require a minimum version of both Restate and the SDK:
- Typed ingress client and the new
/restate/invocation routes: requires Restate >= 1.7 with sdk-rust >= 0.11 - Scope and limit key: requires Restate >= 1.7 with sdk-rust >= 0.11
Contributing
Weβre excited if you join the Restate community and start contributing! Whether it is feature requests, bug reports, ideas & feedback or PRs, we appreciate any and all contributions. We know that your time is precious and, therefore, deeply value any effort to contribute!
Building the SDK locally
Prerequisites:
To build and test the SDK:
just verify
Releasing
You need the Rust toolchain. To verify:
just verify
To release you must be part of the owners team.
To release we use cargo-release.
cargo install cargo-release
Before releasing you need to log into crates.io for which you have to create an API token on https://crates.io/me
cargo login
You might have to use the +nightly toolchain because of releasing multiple crates at once.
First try the dry-run:
cargo +nightly release <VERSION> --exclude test-services --workspace
If everything looks good run with --execute
cargo +nightly release <VERSION> --exclude test-services --workspace --execute