mirror of https://github.com/dapr/rust-sdk.git
Added metadata argument for state api (#26)
This commit is contained in:
parent
53634a4d83
commit
022817e9bf
|
@ -64,6 +64,9 @@ message GetStateRequest {
|
|||
|
||||
// The read consistency of the state store.
|
||||
common.v1.StateOptions.StateConsistency consistency = 3;
|
||||
|
||||
// The metadata which will be sent to state store components.
|
||||
map<string,string> metadata = 4;
|
||||
}
|
||||
|
||||
// GetBulkStateRequest is the message to get a list of key-value states from specific state store.
|
||||
|
@ -76,6 +79,9 @@ message GetBulkStateRequest {
|
|||
|
||||
// The number of parallel operations executed on the state store for a get operation.
|
||||
int32 parallelism = 3;
|
||||
|
||||
// The metadata which will be sent to state store components.
|
||||
map<string,string> metadata = 4;
|
||||
}
|
||||
|
||||
// GetBulkStateResponse is the response conveying the list of state values.
|
||||
|
@ -123,6 +129,9 @@ message DeleteStateRequest {
|
|||
// State operation options which includes concurrency/
|
||||
// consistency/retry_policy.
|
||||
common.v1.StateOptions options = 4;
|
||||
|
||||
// The metadata which will be sent to state store components.
|
||||
map<string,string> metadata = 5;
|
||||
}
|
||||
|
||||
// SaveStateRequest is the message to save multiple states into state store.
|
||||
|
|
|
@ -22,14 +22,14 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||
|
||||
println!("Successfully saved!");
|
||||
|
||||
let get_response = client.get_state("statestore", "hello").await?;
|
||||
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").await?;
|
||||
client.delete_state("statestore", "hello", None).await?;
|
||||
|
||||
// validate if the value was successfully deleted
|
||||
let del_result = client.get_state("statestore", "hello").await?;
|
||||
let del_result = client.get_state("statestore", "hello", None).await?;
|
||||
|
||||
// should print "[]" upon successful delete
|
||||
println!("Deleted value: {:?}", del_result.data);
|
||||
|
|
|
@ -46,7 +46,11 @@ impl ListTopicSubscriptionsResponse {
|
|||
|
||||
impl TopicSubscription {
|
||||
/// Create a new `TopicSubscription` for a give topic.
|
||||
pub fn new(pubsub_name: String, topic: String, metadata: Option<HashMap<String, String>>) -> Self {
|
||||
pub fn new(
|
||||
pubsub_name: String,
|
||||
topic: String,
|
||||
metadata: Option<HashMap<String, String>>,
|
||||
) -> Self {
|
||||
let mut topic_subscription = TopicSubscription {
|
||||
pubsub_name,
|
||||
topic,
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
use std::collections::HashMap;
|
||||
|
||||
use async_trait::async_trait;
|
||||
use dapr::proto::{common::v1 as common_v1, runtime::v1 as dapr_v1};
|
||||
use prost_types::Any;
|
||||
|
@ -80,7 +82,12 @@ impl<T: DaprInterface> Client<T> {
|
|||
/// * `pubsub_name` - Name of the pubsub component
|
||||
/// * `topic` - Pubsub topic.
|
||||
/// * `data` - The data which will be published to topic.
|
||||
pub async fn publish_event<S>(&mut self, pubsub_name: S, topic: S, data: Vec<u8>) -> Result<(), Error>
|
||||
pub async fn publish_event<S>(
|
||||
&mut self,
|
||||
pubsub_name: S,
|
||||
topic: S,
|
||||
data: Vec<u8>,
|
||||
) -> Result<(), Error>
|
||||
where
|
||||
S: Into<String>,
|
||||
{
|
||||
|
@ -118,14 +125,25 @@ impl<T: DaprInterface> Client<T> {
|
|||
///
|
||||
/// * `store_name` - The name of state store.
|
||||
/// * `key` - The key of the desired state.
|
||||
pub async fn get_state<S>(&mut self, store_name: S, key: S) -> Result<GetStateResponse, Error>
|
||||
pub async fn get_state<S>(
|
||||
&mut self,
|
||||
store_name: S,
|
||||
key: S,
|
||||
metadata: Option<HashMap<String, String>>,
|
||||
) -> Result<GetStateResponse, Error>
|
||||
where
|
||||
S: Into<String>,
|
||||
{
|
||||
let mut mdata = HashMap::<String, String>::new();
|
||||
if let Some(m) = metadata {
|
||||
mdata = m;
|
||||
}
|
||||
|
||||
self.0
|
||||
.get_state(GetStateRequest {
|
||||
store_name: store_name.into(),
|
||||
key: key.into(),
|
||||
metadata: mdata,
|
||||
..Default::default()
|
||||
})
|
||||
.await
|
||||
|
@ -156,14 +174,25 @@ impl<T: DaprInterface> Client<T> {
|
|||
///
|
||||
/// * `store_name` - The name of state store.
|
||||
/// * `key` - The key of the desired state.
|
||||
pub async fn delete_state<S>(&mut self, store_name: S, key: S) -> Result<(), Error>
|
||||
pub async fn delete_state<S>(
|
||||
&mut self,
|
||||
store_name: S,
|
||||
key: S,
|
||||
metadata: Option<HashMap<String, String>>,
|
||||
) -> Result<(), Error>
|
||||
where
|
||||
S: Into<String>,
|
||||
{
|
||||
let mut mdata = HashMap::<String, String>::new();
|
||||
if let Some(m) = metadata {
|
||||
mdata = m;
|
||||
}
|
||||
|
||||
self.0
|
||||
.delete_state(DeleteStateRequest {
|
||||
store_name: store_name.into(),
|
||||
key: key.into(),
|
||||
metadata: mdata,
|
||||
..Default::default()
|
||||
})
|
||||
.await
|
||||
|
|
Loading…
Reference in New Issue