Skip to main content

Crate mecha10_messaging

Crate mecha10_messaging 

Source
Expand description

Mecha10 Messaging Layer

This crate provides a Redis Streams-based pub/sub messaging system for inter-node communication in the Mecha10 framework.

§Features

  • Type-safe message serialization/deserialization
  • Redis Streams backend for reliable message delivery
  • Topic-based routing
  • Consumer groups for load balancing
  • Message acknowledgment and retry
  • Automatic reconnection

§Example

use mecha10_messaging::{MessageBus, Message};
use serde::{Deserialize, Serialize};

#[derive(Debug, Serialize, Deserialize)]
struct LaserScan {
    ranges: Vec<f32>,
    timestamp: u64,
}

let mut bus = MessageBus::connect("redis://localhost:6379", "robot-1").await?;

// Subscribe to topic
let mut rx = bus.subscribe::<LaserScan>("/scan", "processing").await?;

// Publish message
let scan = LaserScan { ranges: vec![1.0, 2.0, 3.0], timestamp: 12345 };
bus.publish("/scan", &scan).await?;

// Receive message
if let Some(msg) = rx.recv().await {
    println!("Received scan: {:?}", msg.payload);
    msg.ack().await?;
}

Structs§

Message
A message envelope containing metadata and payload
MessageBus
Message bus for pub/sub communication
RetryConfig
Configuration for connection retry logic
Subscriber
Subscriber handle for receiving messages

Enums§

MessagingError
Messaging errors

Type Aliases§

Result
Result type for messaging operations