Expand description
Session management for ordered message processing.
This module provides a generic framework for session key generation that enables ordered message processing for any domain. Session keys group related messages to ensure they are processed in FIFO order.
§Design Philosophy
This module is intentionally domain-agnostic. It provides the infrastructure for session-based ordering without assuming any specific message structure or business domain (GitHub events, e-commerce orders, IoT telemetry, etc.).
§Core Concepts
- SessionKeyGenerator: Trait for extracting session keys from messages
- Session Keys: Strings that group related messages for ordered processing
- Message Metadata: Messages provide metadata via the
SessionKeyExtractortrait
§Usage Pattern
- Implement
SessionKeyExtractorfor your message type - Implement
SessionKeyGeneratorfor your domain-specific strategy - Use the generator to produce session IDs when sending messages to queues
§Example
use queue_runtime::sessions::{SessionKeyGenerator, SessionKeyExtractor};
use queue_runtime::message::SessionId;
use std::collections::HashMap;
// Your domain message type
struct OrderEvent {
order_id: String,
customer_id: String,
}
// Implement metadata extraction
impl SessionKeyExtractor for OrderEvent {
fn get_metadata(&self, key: &str) -> Option<String> {
match key {
"order_id" => Some(self.order_id.clone()),
"customer_id" => Some(self.customer_id.clone()),
_ => None,
}
}
}
// Implement your session strategy
struct OrderSessionStrategy;
impl SessionKeyGenerator for OrderSessionStrategy {
fn generate_key(&self, extractor: &dyn SessionKeyExtractor) -> Option<SessionId> {
extractor.get_metadata("order_id")
.and_then(|id| SessionId::new(format!("order-{}", id)).ok())
}
}Structs§
- Composite
KeyStrategy - Generates session keys by composing multiple metadata fields.
- Fallback
Strategy - Strategy that tries multiple generators in order, using the first success.
- NoOrdering
Strategy - Strategy that disables session-based ordering.
- Session
Affinity - Mapping of a session to its assigned consumer.
- Session
Affinity Tracker - Tracks session-to-consumer affinity mappings for ordered processing.
- Session
Info - Information about an active session’s lifecycle state.
- Session
Lifecycle Config - Configuration for session lifecycle management.
- Session
Lifecycle Manager - Manages session lifecycles with automatic cleanup and recovery.
- Session
Lock - Represents a lock on a session for exclusive message processing.
- Session
Lock Manager - Manages session locks for concurrent message processing.
- Single
Field Strategy - Generates session keys from a single metadata field.
Traits§
- Session
KeyExtractor - Trait for extracting metadata from messages for session key generation.
- Session
KeyGenerator - Strategy trait for generating session keys from messages.