Crates.io | wasmcloud-actor-messaging |
lib.rs | wasmcloud-actor-messaging |
version | 0.1.2 |
source | src |
created_at | 2021-02-10 16:02:07.937909 |
updated_at | 2021-04-16 15:54:20.775696 |
description | Messaging wasmCloud Actor Interface |
homepage | |
repository | |
max_upload_size | |
id | 353270 |
size | 10,950 |
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.
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(())
}