1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
use crate::{Context, Result, Routed, Worker};
use ockam_core::compat::boxed::Box;
use ockam_core::compat::string::String;
/// A worker which accepts `String`s, and echos them (and the address) to
/// the `debug!` log.
///
/// Mostly intended for use when debugging.
pub struct Echoer;
#[crate::worker]
impl Worker for Echoer {
type Context = Context;
type Message = String;
async fn handle_message(&mut self, ctx: &mut Context, msg: Routed<String>) -> Result<()> {
debug!("Address: {}, Received: {}", ctx.address(), msg);
// Echo the message body back on its return_route.
ctx.send(msg.return_route(), msg.body()).await
}
}