Merge pull request #245 from mikeee/dapr-docs

Update Dapr Rust docs
This commit is contained in:
Mike Nguyen 2024-11-25 12:02:10 +00:00 committed by GitHub
commit 4cfa9a3db2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 23 additions and 16 deletions

View File

@ -8,7 +8,7 @@ All Dapr documentation is hosted at [docs.dapr.io](https://docs.dapr.io), includ
### Rust SDK docs source
Although the docs site code and content is in the [docs repo](https://github.com/dapr/docs), the Go SDK content and images are within the `content` and `static` directories, respectively.
Although the docs site code and content is in the [docs repo](https://github.com/dapr/docs), the Rust SDK content and images are within the `content` and `static` directories, respectively.
This allows separation of roles and expertise between maintainers, and makes it easy to find the docs files you are looking for.

View File

@ -7,10 +7,12 @@ description: How to get up and running with the Dapr Rust SDK
no_list: true
---
The Dapr client package allows you to interact with other Dapr applications from a Rust application.
The Dapr client package allows you to interact with other Dapr applications from
a Rust application.
{{% alert title="Note" color="primary" %}}
The Dapr Rust-SDK is currently in Alpha. Work is underway to bring it to a stable release and will likely involve breaking changes.
The Dapr Rust-SDK is currently in Alpha. Work is underway to bring it to a
stable release and will likely involve breaking changes.
{{% /alert %}}
## Prerequisites
@ -19,7 +21,6 @@ The Dapr Rust-SDK is currently in Alpha. Work is underway to bring it to a stabl
- Initialized [Dapr environment]({{< ref install-dapr-selfhost.md >}})
- [Rust installed](https://www.rust-lang.org/tools/install)
## Import the client package
Add Dapr to your `cargo.toml`
@ -27,10 +28,11 @@ Add Dapr to your `cargo.toml`
```toml
[dependencies]
# Other dependencies
dapr = "0.13.0"
dapr = "0.16.0"
```
You can either reference `dapr::Client` or bind the full path to a new name as follows:
```rust
use dapr::Client as DaprClient
```
@ -38,23 +40,24 @@ use dapr::Client as DaprClient
## Instantiating the Dapr client
```rust
const addr: String = "https://127.0.0.1";
const port: String = "50001";
let addr = "https://127.0.0.1".to_string();
let mut client = dapr::Client::<dapr::client::TonicClient>::connect(addr,
port).await?;
```
## Building blocks
The Rust SDK allows you to interface with the [Dapr building blocks]({{< ref building-blocks >}}).
The Rust SDK allows you to interface with the
[Dapr building blocks]({{< ref building-blocks >}}).
### Service Invocation
To invoke a specific method on another service running with Dapr sidecar, the Dapr client Go SDK provides two options:
To invoke a specific method on another service running with Dapr sidecar, the
Dapr client Go SDK provides two options:
Invoke a service
```rust
let response = client
.invoke_service("service-to-invoke", "method-to-invoke", Some(data))
@ -62,12 +65,13 @@ let response = client
.unwrap();
```
For a full guide on service invocation, visit [How-To: Invoke a service]({{< ref howto-invoke-discover-services.md >}}).
For a full guide on service invocation, visit
[How-To: Invoke a service]({{< ref howto-invoke-discover-services.md >}}).
### State Management
The Dapr Client provides access to these state management methods: `save_state`, `get_state`, `delete_state` that can be used like so:
The Dapr Client provides access to these state management methods: `save_state`
, `get_state`, `delete_state` that can be used like so:
```rust
let store_name = String::from("statestore");
@ -92,10 +96,11 @@ client
Multiple states can be sent with the `save_bulk_states` method.
For a full guide on state management, visit [How-To: Save & get state]({{< ref howto-get-save-state.md >}}).
For a full guide on state management, visit
[How-To: Save & get state]({{< ref howto-get-save-state.md >}}).
### Publish Messages
To publish data onto a topic, the Dapr Go client provides a simple method:
```rust
@ -109,7 +114,9 @@ client
.await?;
```
For a full guide on pub/sub, visit [How-To: Publish & subscribe]({{< ref howto-publish-subscribe.md >}}).
For a full guide on pub/sub, visit
[How-To: Publish & subscribe]({{< ref howto-publish-subscribe.md >}}).
## Related links
[Rust SDK Examples](https://github.com/dapr/rust-sdk/tree/master/examples)