Skip to main content

alien_core/app_events/
queue.rs

1use chrono::{DateTime, Utc};
2use serde::{Deserialize, Serialize};
3use std::collections::HashMap;
4
5#[cfg(feature = "openapi")]
6use utoipa::ToSchema;
7
8/// JSON-first message payload that supports both structured JSON and UTF-8 text
9#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
10#[cfg_attr(feature = "openapi", derive(ToSchema))]
11#[serde(tag = "type", rename_all = "lowercase")]
12pub enum MessagePayload {
13    /// JSON-serializable value
14    Json(serde_json::Value),
15    /// UTF-8 text payload
16    Text(String),
17}
18
19/// Standardized queue message structure used by alien-runtime
20///
21/// This structure contains commonly available metadata across all platforms
22/// and a JSON-first payload that handles both structured data and plain text.
23#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
24#[cfg_attr(feature = "openapi", derive(ToSchema))]
25#[serde(rename_all = "camelCase")]
26pub struct QueueMessage {
27    /// Unique message identifier (from messageId/ce-id)
28    pub id: String,
29
30    /// JSON-first message payload
31    pub payload: MessagePayload,
32
33    /// Platform-specific receipt handle for acknowledgment
34    pub receipt_handle: String,
35
36    /// Message timestamp (from SentTimestamp/ce-time/enqueuedTimeUtc)
37    pub timestamp: DateTime<Utc>,
38
39    /// Source queue/topic name (derived from ARN/source/topic)
40    pub source: String,
41
42    /// Message attributes/properties (flattened from messageAttributes/attributes/properties)
43    #[serde(default, skip_serializing_if = "HashMap::is_empty")]
44    pub attributes: HashMap<String, String>,
45
46    /// Delivery attempt count (from ApproximateReceiveCount/deliveryCount, if available)
47    #[serde(skip_serializing_if = "Option::is_none")]
48    pub attempt_count: Option<u32>,
49}