Expand description
§Messaging wasmCloud Actor Interface
This crate provides wasmCloud actors with an interface to the Messaging capability provider. Actors using this
interface must have the claim wasmcloud:messaging
in order to have permission to handle messages, publish
and perform request-response actions. They also must have an active, configured binding to a Messaging capability provider.
§Example:
extern crate wasmcloud_actor_messaging as messaging;
extern crate wasmcloud_actor_core as actor;
extern crate wapc_guest as guest;
use guest::prelude::*;
#[actor::init]
pub fn init() {
messaging::Handlers::register_handle_message(handle_message);
}
/// Reply to a "ping" message with "pong"
fn handle_message(message: messaging::BrokerMessage) -> HandlerResult<()> {
if String::from_utf8(message.body)? == "ping".to_string() {
messaging::default().publish(message.reply_to, "".to_string(), "pong".to_string().into_bytes())?;
}
Ok(())
}
Structs§
- Broker
Message - Incoming message object with an optionally empty reply field
- Handlers
- Host
- Publish
Args - Publish
Response - Indicates if a publish was successful
- Request
Args
Constants§
Functions§
- default
- Creates the default host binding
- deserialize
- The standard function for de-serializing codec structs from a format suitable for message exchange between actor and host. Use of any other function to deserialize could result in breaking incompatibilities.
- host
- Creates a named host binding
- serialize
- The standard function for serializing codec structs into a format that can be used for message exchange between actor and host. Use of any other function to serialize could result in breaking incompatibilities.