-
Notifications
You must be signed in to change notification settings - Fork 62
/
client.rs
37 lines (25 loc) · 1.21 KB
/
client.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// TODO: Handle this issue in the sdk
// Introduce delay so that dapr grpc port is assigned before app tries to connect
std::thread::sleep(std::time::Duration::new(2, 0));
// Set the Dapr address
let addr = "https://127.0.0.1".to_string();
// Create the client
let mut client = dapr::Client::<dapr::client::TonicClient>::connect(addr).await?;
let key = String::from("hello");
let val = String::from("world").into_bytes();
let store_name = String::from("statestore");
// save key-value pair in the state store
client.save_state(store_name, vec![(key, val)]).await?;
println!("Successfully saved!");
let get_response = client.get_state("statestore", "hello", None).await?;
println!("Value is {:?}", String::from_utf8_lossy(&get_response.data));
// delete a value from the state store
client.delete_state("statestore", "hello", None).await?;
// validate if the value was successfully deleted
let del_result = client.get_state("statestore", "hello", None).await?;
// should print "[]" upon successful delete
println!("Deleted value: {:?}", del_result.data);
Ok(())
}