pub struct RpcClient { /* private fields */ }Expand description
Send wasmbus rpc messages
The primary use of RpcClient is providers sending to actors, however providers don’t need to construct this - one is created by HostBridge, which providers create during initialization.
This class is also used by wash and test tools for sending rpc messages to actors and providers. Note that sending to a provider requires an existing link definition, and, the message needs to be signed by a valid cluster key.
This RpcClient does not subscribe to rpc topics. To subscribe, use the nats client api directly.
Implementations§
Source§impl RpcClient
impl RpcClient
Sourcepub fn new(
nats: Client,
host_id: String,
timeout: Option<Duration>,
key_pair: Arc<KeyPair>,
) -> Self
pub fn new( nats: Client, host_id: String, timeout: Option<Duration>, key_pair: Arc<KeyPair>, ) -> Self
Constructs a new RpcClient with an async nats connection. parameters: async nats client, rpc timeout secret key for signing messages, host_id, and optional timeout.
Sourcepub fn set_timeout(&mut self, timeout: Option<Duration>)
pub fn set_timeout(&mut self, timeout: Option<Duration>)
Replace the default timeout with the specified value. If the parameter is None, unsets the default timeout
Sourcepub async fn send_json<Target, Resp>(
&self,
origin: WasmCloudEntity,
target: Target,
lattice: &str,
method: &str,
data: JsonValue,
) -> RpcResult<JsonValue>
pub async fn send_json<Target, Resp>( &self, origin: WasmCloudEntity, target: Target, lattice: &str, method: &str, data: JsonValue, ) -> RpcResult<JsonValue>
Send an rpc message using json-encoded data
Sourcepub async fn send<Target>(
&self,
origin: WasmCloudEntity,
target: Target,
lattice: &str,
message: Message<'_>,
) -> RpcResult<Vec<u8>>where
Target: Into<WasmCloudEntity>,
pub async fn send<Target>(
&self,
origin: WasmCloudEntity,
target: Target,
lattice: &str,
message: Message<'_>,
) -> RpcResult<Vec<u8>>where
Target: Into<WasmCloudEntity>,
Send a wasmbus rpc message by wrapping with an Invocation before sending over nats. ‘target’ may be &str or String for sending to an actor, or a WasmCloudEntity (for actor or provider) If a response is not received within the default timeout, the Error RpcError::Timeout is returned. If the client timeout has been set, this call is equivalent to send_timeout passing in the default timeout.
Sourcepub async fn send_timeout<Target>(
&self,
origin: WasmCloudEntity,
target: Target,
lattice: &str,
message: Message<'_>,
timeout: Duration,
) -> RpcResult<Vec<u8>>where
Target: Into<WasmCloudEntity>,
pub async fn send_timeout<Target>(
&self,
origin: WasmCloudEntity,
target: Target,
lattice: &str,
message: Message<'_>,
timeout: Duration,
) -> RpcResult<Vec<u8>>where
Target: Into<WasmCloudEntity>,
Send a wasmbus rpc message, with a timeout. The rpc message is wrapped with an Invocation before sending over nats. ‘target’ may be &str or String for sending to an actor, or a WasmCloudEntity (for actor or provider) If the timeout expires before the response is received, this returns Error RpcError::Timeout.
Sourcepub async fn request(
&self,
subject: String,
payload: Vec<u8>,
) -> RpcResult<Vec<u8>>
pub async fn request( &self, subject: String, payload: Vec<u8>, ) -> RpcResult<Vec<u8>>
Send a nats message and wait for the response. This can be used for general nats messages, not just wasmbus actor/provider messages. If this client has a default timeout, and a response is not received within the appropriate time, an error will be returned.
Sourcepub async fn publish(&self, subject: String, payload: Vec<u8>) -> RpcResult<()>
pub async fn publish(&self, subject: String, payload: Vec<u8>) -> RpcResult<()>
Send a nats message with no reply-to. Do not wait for a response. This can be used for general nats messages, not just wasmbus actor/provider messages.
pub async fn publish_invocation_response( &self, reply_to: String, response: InvocationResponse, lattice: &str, ) -> RpcResult<()>
pub async fn dechunk( &self, inv: Invocation, lattice: &str, ) -> RpcResult<Invocation>
Sourcepub async fn validate_invocation(
&self,
inv: Invocation,
) -> Result<(Invocation, Claims<Invocation>), String>
pub async fn validate_invocation( &self, inv: Invocation, ) -> Result<(Invocation, Claims<Invocation>), String>
Initial validation of received message. See provider::validate_provider_invocation for second part.