Skip to content

Commit 44f3f46

Browse files
committed
refactor invoke_binding and add invoke_output_binding
Signed-off-by: mikeee <[email protected]>
1 parent bef6e3b commit 44f3f46

File tree

1 file changed

+31
-2
lines changed

1 file changed

+31
-2
lines changed

src/client.rs

+31-2
Original file line numberDiff line numberDiff line change
@@ -51,16 +51,20 @@ impl<T: DaprInterface> Client<T> {
5151
.await
5252
}
5353

54-
/// Invoke an Dapr output binding.
54+
/// Invoke a Dapr output binding.
5555
///
5656
/// # Arguments
5757
///
5858
/// * `name` - The name of the output binding to invoke.
5959
/// * `data` - The data which will be sent to the output binding.
60+
/// * `metadata` - The metadata key-pairs to be sent
61+
/// * `operation` - The operation name for the binding to invoke.
6062
pub async fn invoke_binding<S>(
6163
&mut self,
6264
name: S,
6365
data: Vec<u8>,
66+
metadata: Option<HashMap<String, String>>,
67+
operation: S,
6468
) -> Result<InvokeBindingResponse, Error>
6569
where
6670
S: Into<String>,
@@ -69,11 +73,36 @@ impl<T: DaprInterface> Client<T> {
6973
.invoke_binding(InvokeBindingRequest {
7074
name: name.into(),
7175
data,
72-
..Default::default()
76+
metadata: metadata.unwrap_or_default(),
77+
operation: operation.into(),
7378
})
7479
.await
7580
}
7681

82+
/// Invoke a Dapr output binding without expecting a response.
83+
///
84+
/// # Arguments
85+
///
86+
/// * `name` - The name of the output binding to invoke.
87+
/// * `operation` - The operation name for the binding to invoke.
88+
pub async fn invoke_output_binding<S>(&mut self, name: S, operation: S) -> Result<(), Error>
89+
where
90+
S: Into<String>,
91+
{
92+
let result = self
93+
.0
94+
.invoke_binding(InvokeBindingRequest {
95+
name: name.into(),
96+
operation: operation.into(),
97+
..Default::default()
98+
})
99+
.await;
100+
match result {
101+
Ok(_) => Ok(()),
102+
Err(_) => Err(result.unwrap_err()),
103+
}
104+
}
105+
77106
/// Publish a payload to multiple consumers who are listening on a topic.
78107
///
79108
/// Dapr guarantees at least once semantics for this endpoint.

0 commit comments

Comments
 (0)