actr-mailbox 0.1.0

Persistent mailbox layer for the Actor-RTC framework, backed by SQLite.
docs.rs failed to build actr-mailbox-0.1.0
Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
Visit the last successful build: actr-mailbox-0.1.5

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(())
}