Expand description
§Data Model Module
Core data models and message representations for Azure Service Bus operations. This module provides the fundamental data structures used throughout the Quetty application for representing Service Bus messages, their states, and associated metadata.
§Message Representation
The primary model is MessageModel, which provides a unified representation
of Azure Service Bus messages that is optimized for terminal UI display and
manipulation. It handles the complexities of Azure’s message format while
providing a clean, consistent interface.
§Key Features
§Flexible Message Body Handling
- JSON Messages - Automatic parsing and validation of JSON message bodies
- Raw Text Messages - Support for plain text and binary message content
- Lossless Conversion - Preserves original message data during transformation
§Message State Management
- State Tracking - Comprehensive message state representation
- State Transitions - Support for all Azure Service Bus message states
- Status Visualization - UI-friendly state representation
§Serialization Support
- JSON Export - Full message serialization for export and analysis
- Timestamp Handling - ISO8601 timestamp serialization
- Type Safety - Strongly typed message components
§Core Types
§MessageModel
The primary message representation containing all essential message data:
use quetty_server::model::{MessageModel, MessageState, BodyData};
use azure_core::time::OffsetDateTime;
// Create a new message model
let message = MessageModel::new(
12345, // sequence number
"msg-001".to_string(), // message ID
OffsetDateTime::now_utc(), // enqueued timestamp
0, // delivery count
MessageState::Active, // current state
BodyData::RawString("Hello!".to_string()) // message body
);
println!("Message ID: {}", message.id);
println!("State: {:?}", message.state);§MessageState
Represents all possible states of a Service Bus message:
use quetty_server::model::MessageState;
let state = MessageState::Active;
match state {
MessageState::Active => println!("Message is available for processing"),
MessageState::Deferred => println!("Message is deferred for later processing"),
MessageState::Scheduled => println!("Message is scheduled for future delivery"),
MessageState::DeadLettered => println!("Message is in dead letter queue"),
MessageState::Completed => println!("Message processing completed"),
MessageState::Abandoned => println!("Message processing abandoned"),
}§BodyData
Flexible message body representation supporting both JSON and raw text:
use quetty_server::model::BodyData;
use serde_json::json;
// JSON message body
let json_body = BodyData::ValidJson(json!({
"type": "order",
"id": 12345,
"customer": "Jane Doe"
}));
// Raw text message body
let text_body = BodyData::RawString("Plain text message".to_string());
// Bodies serialize appropriately for JSON export
let serialized = serde_json::to_string(&json_body)?;§Message Conversion
§From Azure Service Bus Messages
Automatic conversion from Azure SDK message types:
use quetty_server::model::MessageModel;
use azservicebus::prelude::ServiceBusPeekedMessage;
use std::convert::TryFrom;
// Convert single message
let azure_message: ServiceBusPeekedMessage = get_message_from_azure();
let message_model = MessageModel::try_from(azure_message)?;
// Convert batch of messages with error handling
let azure_messages: Vec<ServiceBusPeekedMessage> = get_messages_from_azure();
let valid_messages = MessageModel::try_convert_messages_collect(azure_messages);
println!("Successfully converted {} messages", valid_messages.len());§Error Handling
Robust error handling for message conversion:
use quetty_server::model::{MessageModel, MessageModelError};
use std::convert::TryFrom;
match MessageModel::try_from(azure_message) {
Ok(message) => {
println!("Successfully converted message: {}", message.id);
}
Err(MessageModelError::MissingMessageId) => {
eprintln!("Message is missing required ID field");
}
Err(MessageModelError::MissingMessageBody) => {
eprintln!("Message is missing body content");
}
Err(MessageModelError::MissingDeliveryCount) => {
eprintln!("Message is missing delivery count");
}
Err(MessageModelError::JsonError(e)) => {
eprintln!("JSON parsing error: {}", e);
}
}§Integration with UI
Models are designed for seamless integration with the terminal UI:
- Display Optimization - Fields optimized for table and detail views
- Sorting Support - Comparable fields for list sorting
- Color Coding - State-based visual indicators
- Export Support - JSON serialization for data export
§Performance Considerations
- Efficient Conversion - Minimal overhead in Azure message conversion
- Memory Optimization - Appropriate use of owned vs. borrowed data
- Batch Processing - Optimized batch conversion for large message sets
- Error Tolerance - Graceful handling of malformed messages in batches
§Thread Safety
All model types implement appropriate traits for concurrent use:
Clonefor efficient copyingSendandSyncfor thread safetyDebugfor development and logging
Structs§
- Message
Model - Unified message model representing Azure Service Bus messages.
Enums§
- Body
Data - Flexible representation of message body content supporting both JSON and raw text.
- Message
Model Error - Message
State - Represents the current state of a message within Azure Service Bus.