wasmcloud_runtime::component

Trait Messaging0_3

Source
pub trait Messaging0_3 {
    // Required methods
    fn connect(
        &self,
        name: String,
    ) -> impl Future<Output = Result<Result<Box<dyn Client + Send + Sync>, Error>>> + Send;
    fn send(
        &self,
        client: &(dyn Client + Send + Sync),
        topic: Topic,
        message: Message,
    ) -> impl Future<Output = Result<Result<(), Error>>> + Send;
    fn request(
        &self,
        client: &(dyn Client + Send + Sync),
        topic: Topic,
        message: &Message,
        options: Option<RequestOptions>,
    ) -> impl Future<Output = Result<Result<Vec<Box<dyn HostMessage + Send + Sync>>, Error>>> + Send;
    fn reply(
        &self,
        reply_to: &Message,
        message: Message,
    ) -> impl Future<Output = Result<Result<(), Error>>> + Send;
}
Expand description

wasmcloud:messaging abstraction

Required Methods§

Source

fn connect( &self, name: String, ) -> impl Future<Output = Result<Result<Box<dyn Client + Send + Sync>, Error>>> + Send

Establish connection to a message-exchange service (e.g., buffer, broker, etc.).

Source

fn send( &self, client: &(dyn Client + Send + Sync), topic: Topic, message: Message, ) -> impl Future<Output = Result<Result<(), Error>>> + Send

Sends the message using the given client.

Source

fn request( &self, client: &(dyn Client + Send + Sync), topic: Topic, message: &Message, options: Option<RequestOptions>, ) -> impl Future<Output = Result<Result<Vec<Box<dyn HostMessage + Send + Sync>>, Error>>> + Send

Performs a blocking request/reply operation with an optional set of request options.

The behavior of this function is largely dependent on the options given to the function. If no options are provided, then the request/reply operation will block until a single message is received in response. If a timeout is provided, then the request/reply operation will block for the specified amount of time before returning an error if no messages were received (or the list of messages that were received). If both a timeout and an expected number of replies are provided, the function should return when either condition is met (whichever comes first)—e.g., (1) if no replies were received within the timeout return an error, (2) if the maximum expected number of replies were received before timeout, return the list of messages, or (3) if the timeout is reached before the expected number of replies, return the list of messages received up to that point.

Source

fn reply( &self, reply_to: &Message, message: Message, ) -> impl Future<Output = Result<Result<(), Error>>> + Send

Replies to the given message with the given response message. The details of which topic the message is sent to is up to the implementation. This allows for reply-to details to be handled in the best way possible for the underlying messaging system.

Please note that this reply functionality is different than something like HTTP because there are several use cases in which a reply might not be required for every message (so this would be a noop). There are also cases when you might want to reply and then continue processing. Additionally, you might want to reply to a message several times (such as providing an update). So this function is allowed to be called multiple times, unlike something like HTTP where the reply is sent and the connection is closed.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§