wasmcloud_actor_messaging/
lib.rs

1#![doc(html_logo_url = "https://avatars2.githubusercontent.com/u/52050279?s=200&v=4")]
2//! # Messaging wasmCloud Actor Interface
3//!
4//! This crate provides wasmCloud actors with an interface to the Messaging capability provider. Actors using this
5//! interface must have the claim `wasmcloud:messaging` in order to have permission to handle messages, publish
6//! and perform request-response actions. They also must have an active, configured binding to a Messaging capability provider.
7//!
8//! # Example:
9//! ```rust
10//! extern crate wasmcloud_actor_messaging as messaging;
11//! extern crate wasmcloud_actor_core as actor;
12//! extern crate wapc_guest as guest;
13//! use guest::prelude::*;
14//!
15//! #[actor::init]
16//! pub fn init() {
17//!     messaging::Handlers::register_handle_message(handle_message);
18//! }
19//!
20//! /// Reply to a "ping" message with "pong"
21//! fn handle_message(message: messaging::BrokerMessage) -> HandlerResult<()> {
22//!     if String::from_utf8(message.body)? == "ping".to_string() {
23//!         messaging::default().publish(message.reply_to, "".to_string(), "pong".to_string().into_bytes())?;
24//!     }
25//!     Ok(())
26//! }
27//!
28//! ```
29
30mod generated;
31pub use generated::*;
32
33pub const OP_HANDLE_MESSAGE: &str = "HandleMessage";