MessageModel

Struct MessageModel 

Source
pub struct MessageModel {
    pub sequence: i64,
    pub id: String,
    pub enqueued_at: OffsetDateTime,
    pub delivery_count: usize,
    pub state: MessageState,
    pub body: BodyData,
}
Expand description

Unified message model representing Azure Service Bus messages.

This struct provides a clean, consistent representation of Service Bus messages that is optimized for terminal UI display and manipulation. It handles the complexities of Azure’s message format while providing type safety and serialization support.

§Fields

  • sequence - Unique sequence number assigned by Azure Service Bus
  • id - Message identifier (typically a GUID)
  • enqueued_at - Timestamp when the message was enqueued
  • delivery_count - Number of delivery attempts for this message
  • state - Current state of the message in the queue
  • body - Message content (JSON or raw text)

§Examples

§Creating a New Message Model

use quetty_server::model::{MessageModel, MessageState, BodyData};
use azure_core::time::OffsetDateTime;

let message = MessageModel::new(
    12345,
    "550e8400-e29b-41d4-a716-446655440000".to_string(),
    OffsetDateTime::now_utc(),
    0,
    MessageState::Active,
    BodyData::RawString("Hello, Service Bus!".to_string())
);

assert_eq!(message.sequence, 12345);
assert_eq!(message.delivery_count, 0);
assert_eq!(message.state, MessageState::Active);

§Converting from Azure Messages

use quetty_server::model::MessageModel;
use azservicebus::prelude::ServiceBusPeekedMessage;
use std::convert::TryFrom;

// Convert single message with error handling
let azure_message: ServiceBusPeekedMessage = get_azure_message();
match MessageModel::try_from(azure_message) {
    Ok(message) => {
        println!("Converted message: {} (sequence: {})",
                 message.id, message.sequence);
    }
    Err(e) => eprintln!("Conversion failed: {:?}", e),
}

§Batch Conversion

use quetty_server::model::MessageModel;
use azservicebus::prelude::ServiceBusPeekedMessage;

let azure_messages: Vec<ServiceBusPeekedMessage> = get_azure_messages();
let valid_messages = MessageModel::try_convert_messages_collect(azure_messages);

println!("Successfully converted {} messages", valid_messages.len());
for message in valid_messages {
    println!("  - {} ({})", message.id, message.state);
}

§JSON Serialization

use quetty_server::model::{MessageModel, MessageState, BodyData};
use serde_json::json;

let message = MessageModel {
    sequence: 12345,
    id: "test-message".to_string(),
    enqueued_at: OffsetDateTime::now_utc(),
    delivery_count: 0,
    state: MessageState::Active,
    body: BodyData::ValidJson(json!({"type": "test", "data": "value"})),
};

// Serialize to JSON for export or API responses
let json_string = serde_json::to_string_pretty(&message)?;
println!("Exported message:\n{}", json_string);

§Thread Safety

MessageModel implements Clone, Send, and Sync, making it safe to share across threads and async tasks. This is essential for the concurrent nature of the terminal UI application.

§Performance Notes

  • Cloning is relatively inexpensive due to reference counting for large data
  • Serialization is optimized for both human-readable and compact formats
  • Memory usage is minimized through efficient string storage

Fields§

§sequence: i64

Unique sequence number assigned by Azure Service Bus for message ordering

§id: String

Message identifier, typically a GUID string

§enqueued_at: OffsetDateTime

UTC timestamp when the message was originally enqueued

§delivery_count: usize

Number of times delivery has been attempted for this message

§state: MessageState

Current state of the message within the Service Bus queue

§body: BodyData

Message content, either parsed JSON or raw text

Implementations§

Source§

impl MessageModel

Source

pub fn new( sequence: i64, id: String, enqueued_at: OffsetDateTime, delivery_count: usize, state: MessageState, body: BodyData, ) -> Self

Source

pub fn try_convert_messages_collect( messages: Vec<ServiceBusPeekedMessage>, ) -> Vec<MessageModel>

Trait Implementations§

Source§

impl Clone for MessageModel

Source§

fn clone(&self) -> MessageModel

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for MessageModel

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for MessageModel

Source§

fn eq(&self, other: &MessageModel) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for MessageModel

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl TryFrom<ServiceBusPeekedMessage> for MessageModel

Source§

type Error = MessageModelError

The type returned in the event of a conversion error.
Source§

fn try_from(msg: ServiceBusPeekedMessage) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl StructuralPartialEq for MessageModel

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> SendBound for T
where T: Send,