pub struct Message {
pub id: String,
pub topic: String,
pub payload: Vec<u8>,
pub sender: String,
pub metadata: HashMap<String, String>,
pub created_at: i64,
}Fields§
§id: String§topic: String§payload: Vec<u8>§sender: String§metadata: HashMap<String, String>§created_at: i64Implementations§
Source§impl Message
impl Message
Sourcepub fn new(
topic: impl Into<String>,
payload: Vec<u8>,
sender: impl Into<String>,
) -> Self
pub fn new( topic: impl Into<String>, payload: Vec<u8>, sender: impl Into<String>, ) -> Self
Examples found in repository?
examples/mesh_architecture.rs (line 38)
27 async fn on_message(&mut self, msg: Message, _ctx: &mut AgentContext) -> Result<()> {
28 let content = String::from_utf8_lossy(&msg.payload);
29 println!("[Worker] Received task from {}: {}", msg.sender, content);
30
31 // Simulate processing
32 tokio::time::sleep(Duration::from_millis(500)).await;
33
34 // Send response
35 let response = format!("Processed: {}", content);
36 println!("[Worker] Sending response: {}", response);
37
38 let reply_msg = Message::new("result", response.into_bytes(), self.name());
39 self.mesh.send(reply_msg, &msg.sender).await?;
40
41 Ok(())
42 }
43}
44
45// --- Manager Agent ---
46struct ManagerAgent {
47 mesh: Arc<LocalMesh>,
48 completion_notify: Arc<Notify>,
49}
50
51#[async_trait]
52impl Agent for ManagerAgent {
53 fn name(&self) -> String {
54 "manager".to_string()
55 }
56
57 async fn on_start(&mut self, _ctx: &mut AgentContext) -> Result<()> {
58 println!("[Manager] Started. Sending task to worker...");
59
60 // Send a task to the worker
61 let task_msg = Message::new("task", b"Analyze data".to_vec(), self.name());
62 self.mesh.send(task_msg, "worker").await?;
63
64 Ok(())
65 }pub fn correlation_id(&self) -> Option<String>
pub fn set_correlation_id(&mut self, id: &str)
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Message
impl<'de> Deserialize<'de> for Message
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl Freeze for Message
impl RefUnwindSafe for Message
impl Send for Message
impl Sync for Message
impl Unpin for Message
impl UnwindSafe for Message
Blanket Implementations§
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§unsafe fn clone_to_uninit(&self, dest: *mut u8)
unsafe fn clone_to_uninit(&self, dest: *mut u8)
🔬This is a nightly-only experimental API. (
clone_to_uninit)Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more