Expand description
§Actor-RTC Mailbox Layer
🗄️ Actor-RTC 框架的持久化邮箱层,由 SQLite 支持。
§核心功能
- 消息持久化: 可靠的消息队列和邮箱存储
- Dead Letter Queue: 毒消息隔离和人工干预
§快速开始
use actr_mailbox::prelude::*;
use actr_protocol::{ActrId, Realm, ActrType};
use actr_protocol::prost::Message as ProstMessage;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// 创建 SQLite 邮箱存储
let mailbox = SqliteMailbox::new("./data/mailbox.db").await?;
// 创建发送者 ActrId 并序列化
let sender = ActrId {
realm: Realm { realm_id: 1 },
serial_number: 1000,
r#type: ActrType {
manufacturer: "example".to_string(),
name: "TestActor".to_string(),
},
};
let mut from_bytes = Vec::new();
sender.encode(&mut from_bytes)?;
let message = b"Hello, World!".to_vec();
// 入队消息(from 为发送方 ActrId 的 Protobuf bytes)
let message_id = mailbox.enqueue(from_bytes, message, MessagePriority::Normal).await?;
// 出队消息
let messages = mailbox.dequeue().await?;
println!("Retrieved {} messages", messages.len());
// 确认消息
if let Some(msg) = messages.first() {
mailbox.ack(msg.id).await?;
}
Ok(())
}Re-exports§
pub use error::StorageError;pub use error::StorageResult;pub use mailbox::Mailbox;pub use mailbox::MailboxStats;pub use mailbox::MessagePriority;pub use mailbox::MessageRecord;pub use mailbox::MessageStatus;pub use dlq::DeadLetterQueue;pub use dlq::DlqQuery;pub use dlq::DlqRecord;pub use dlq::DlqStats;pub use sqlite::SqliteConfig;pub use sqlite::SqliteMailbox;pub use sqlite_dlq::SqliteDeadLetterQueue;
Modules§
- dlq
- Dead Letter Queue (DLQ)
- error
- 存储层错误定义
- mailbox
- Actor Mailbox
- prelude
- 邮箱层常用类型和 trait 的便利导入
- sqlite
- SQLite 存储后端实现
- sqlite_
dlq - SQLite implementation of Dead Letter Queue
Structs§
Enums§
- Actr
Error - Errors for actor identity parsing and formatting