Struct wasmbus_rpc::rpc_client::RpcClient
source · [−]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
sourceimpl RpcClient
impl RpcClient
sourcepub fn new(
nats: Connection,
lattice_prefix: &str,
key: KeyPair,
host_id: String,
timeout: Option<Duration>
) -> Self
pub fn new(
nats: Connection,
lattice_prefix: &str,
key: KeyPair,
host_id: String,
timeout: Option<Duration>
) -> Self
Constructs a new RpcClient for the async nats connection. parameters: async nats client, lattice rpc prefix (usually “default”), secret key for signing messages, and host_id
sourcepub fn get_async(&self) -> Option<Connection>
pub fn get_async(&self) -> Option<Connection>
convenience method for returning async client If the client is not the correct type, returns None
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, Arg, Resp>(
&self,
origin: WasmCloudEntity,
target: Target,
method: &str,
data: JsonValue
) -> Result<JsonValue, RpcError> where
Arg: DeserializeOwned + Serialize,
Resp: DeserializeOwned + Serialize,
Target: Into<WasmCloudEntity>,
pub async fn send_json<Target, Arg, Resp>(
&self,
origin: WasmCloudEntity,
target: Target,
method: &str,
data: JsonValue
) -> Result<JsonValue, RpcError> where
Arg: DeserializeOwned + Serialize,
Resp: DeserializeOwned + Serialize,
Target: Into<WasmCloudEntity>,
Send an rpc message using json-encoded data
sourcepub async fn send<Target>(
&self,
origin: WasmCloudEntity,
target: Target,
message: Message<'_>
) -> Result<Vec<u8>, RpcError> where
Target: Into<WasmCloudEntity>,
pub async fn send<Target>(
&self,
origin: WasmCloudEntity,
target: Target,
message: Message<'_>
) -> Result<Vec<u8>, RpcError> 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 nats client is sync, this can block the current thread. 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,
message: Message<'_>,
timeout: Duration
) -> Result<Vec<u8>, RpcError> where
Target: Into<WasmCloudEntity>,
pub async fn send_timeout<Target>(
&self,
origin: WasmCloudEntity,
target: Target,
message: Message<'_>,
timeout: Duration
) -> Result<Vec<u8>, RpcError> 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 nats client is sync, this can block the current thread until either the response is received, or the timeout expires. If the timeout expires before the response is received, this returns Error RpcError::Timeout.
sourcepub async fn request(
&self,
subject: &str,
data: &[u8]
) -> Result<Vec<u8>, RpcError>
pub async fn request(
&self,
subject: &str,
data: &[u8]
) -> Result<Vec<u8>, RpcError>
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.
Trait Implementations
Auto Trait Implementations
impl !RefUnwindSafe for RpcClient
impl Send for RpcClient
impl Sync for RpcClient
impl Unpin for RpcClient
impl !UnwindSafe for RpcClient
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<T> Pointable for T
impl<T> Pointable for T
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcepub fn to_owned(&self) -> T
pub fn to_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. Read more
sourcepub fn clone_into(&self, target: &mut T)
pub fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more