common_meta/heartbeat/
mailbox.rs1use std::sync::Arc;
16
17use common_telemetry::tracing_context::TracingContext;
18use tokio::sync::mpsc::Sender;
19use tokio::sync::mpsc::error::SendError;
20
21use crate::instruction::{Instruction, InstructionReply};
22
23pub type IncomingMessage = (MessageMeta, TracingContext, Instruction);
24pub type OutgoingMessage = (MessageMeta, InstructionReply);
25
26#[derive(Debug, PartialEq, Eq, Clone)]
27pub struct MessageMeta {
28 pub id: u64,
29 pub subject: String,
30 pub to: String,
31 pub from: String,
32}
33
34impl MessageMeta {
35 #[cfg(any(test, feature = "testing"))]
36 pub fn new_test(id: u64, subject: &str, to: &str, from: &str) -> Self {
37 MessageMeta {
38 id,
39 subject: subject.to_string(),
40 to: to.to_string(),
41 from: from.to_string(),
42 }
43 }
44}
45
46pub struct HeartbeatMailbox {
47 sender: Sender<OutgoingMessage>,
48}
49
50impl HeartbeatMailbox {
51 pub fn new(sender: Sender<OutgoingMessage>) -> Self {
52 Self { sender }
53 }
54
55 pub async fn send(&self, message: OutgoingMessage) -> Result<(), SendError<OutgoingMessage>> {
56 self.sender.send(message).await
57 }
58}
59
60pub type MailboxRef = Arc<HeartbeatMailbox>;