@@ -7,7 +7,9 @@ description: How to get up and running with the Dapr Rust SDK
7
7
no_list : true
8
8
---
9
9
10
- The Dapr client package allows you to interact with other Dapr applications from a Go application.
10
+ The Dapr client package allows you to interact with other Dapr applications from a Rust application.
11
+
12
+ > ** Note:** The Rust SDK is currently in Alpha/WIP state and is constantly evolving.
11
13
12
14
## Prerequisites
13
15
@@ -31,5 +33,66 @@ You can either reference `dapr::Client` or bind the full path to a new name as f
31
33
use dapr :: Client as DaprClient
32
34
```
33
35
36
+
37
+ ## Building blocks
38
+
39
+ The Rust SDK allows you to interface with the [Dapr building blocks]({{< ref building- blocks >}}).
40
+
41
+ ### Service Invocation
42
+
43
+ To invoke a specific method on another service running with Dapr sidecar, the Dapr client Go SDK provides two options:
44
+
45
+ Invoke a service
46
+ ```rust
47
+ let response = client
48
+ . invoke_service("service- to- invoke", "method- to- invoke", Some (data))
49
+ . await
50
+ . unwrap();
51
+ ```
52
+
53
+
54
+ For a full guide on service invocation, visit [ How-To: Invoke a service] ({{< ref howto-invoke-discover-services.md >}}).
55
+
56
+ ### State Management
57
+
58
+ The Dapr Client provides access to these state management methods: ` save_state ` , ` get_state ` , ` delete_state ` that can be used like so:
59
+
60
+ ``` rust
61
+ let store_name = " store-name" ;
62
+ let state_key = " state-key" ;
63
+
64
+ let states = vec! [(state_key , (" state-value" ). as_bytes (). to_vec ())];
65
+
66
+ // save state with the key "state-key" and value "state-value"
67
+ client . save_state (store_name , states ). await ? ;
68
+
69
+ // get state for key "state-key"
70
+ let response = client . get_state (store_name , state_key , None ). await . unwrap ();
71
+
72
+ // delete state for key "state-key"
73
+ client . delete_state (store_name , state_key , None ). await ? ;
74
+ ```
75
+
76
+ > ** Note:** The ` save_state ` method currently performs a 'bulk' save but this will be refactored
77
+
78
+
79
+ For a full guide on state management, visit [ How-To: Save & get state] ({{< ref howto-get-save-state.md >}}).
80
+
81
+ ### Publish Messages
82
+ To publish data onto a topic, the Dapr Go client provides a simple method:
83
+
84
+ ``` rust
85
+ let pubsub_name = " pubsub-name" . to_string ();
86
+ let pubsub_topic = " topic-name" . to_string ();
87
+ let pubsub_content_type = " text/plain" . to_string ();
88
+
89
+ let data = " content" . to_string (). into_bytes ();
90
+ client
91
+ . publish_event (pubsub_name , pubsub_topic , pubsub_content_type , data , None )
92
+ . await ? ;
93
+ ```
94
+
95
+ For a full guide on pub/sub, visit [ How-To: Publish & subscribe] ({{< ref howto-publish-subscribe.md >}}).
96
+
34
97
## Related links
35
98
[ Rust SDK Examples] ( https://github.com/dapr/rust-sdk/tree/master/examples )
0 commit comments