From 44f3f46617c0559ffc4c2278ce98f1402a096f35 Mon Sep 17 00:00:00 2001 From: mikeee Date: Tue, 27 Feb 2024 15:17:20 +0000 Subject: [PATCH] refactor invoke_binding and add invoke_output_binding Signed-off-by: mikeee --- src/client.rs | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/src/client.rs b/src/client.rs index 8b4d675f..4ee45feb 100644 --- a/src/client.rs +++ b/src/client.rs @@ -51,16 +51,20 @@ impl Client { .await } - /// Invoke an Dapr output binding. + /// Invoke a Dapr output binding. /// /// # Arguments /// /// * `name` - The name of the output binding to invoke. /// * `data` - The data which will be sent to the output binding. + /// * `metadata` - The metadata key-pairs to be sent + /// * `operation` - The operation name for the binding to invoke. pub async fn invoke_binding( &mut self, name: S, data: Vec, + metadata: Option>, + operation: S, ) -> Result where S: Into, @@ -69,11 +73,36 @@ impl Client { .invoke_binding(InvokeBindingRequest { name: name.into(), data, - ..Default::default() + metadata: metadata.unwrap_or_default(), + operation: operation.into(), }) .await } + /// Invoke a Dapr output binding without expecting a response. + /// + /// # Arguments + /// + /// * `name` - The name of the output binding to invoke. + /// * `operation` - The operation name for the binding to invoke. + pub async fn invoke_output_binding(&mut self, name: S, operation: S) -> Result<(), Error> + where + S: Into, + { + let result = self + .0 + .invoke_binding(InvokeBindingRequest { + name: name.into(), + operation: operation.into(), + ..Default::default() + }) + .await; + match result { + Ok(_) => Ok(()), + Err(_) => Err(result.unwrap_err()), + } + } + /// Publish a payload to multiple consumers who are listening on a topic. /// /// Dapr guarantees at least once semantics for this endpoint.