aws_lambda_events/event/rabbitmq/
mod.rs

1use serde::{de::DeserializeOwned, Deserialize, Serialize};
2use serde_json::Value;
3use std::collections::HashMap;
4
5use crate::custom_serde::deserialize_lambda_map;
6
7#[derive(Debug, Default, Clone, Eq, PartialEq, Deserialize, Serialize)]
8#[serde(rename_all = "camelCase")]
9pub struct RabbitMqEvent {
10    #[serde(default)]
11    pub event_source: Option<String>,
12    #[serde(default)]
13    pub event_source_arn: Option<String>,
14    #[serde(deserialize_with = "deserialize_lambda_map")]
15    #[serde(default)]
16    #[serde(rename = "rmqMessagesByQueue")]
17    pub messages_by_queue: HashMap<String, Vec<RabbitMqMessage>>,
18    /// Catchall to catch any additional fields that were present but not explicitly defined by this struct.
19    /// Enabled with Cargo feature `catch-all-fields`.
20    /// If `catch-all-fields` is disabled, any additional fields that are present will be ignored.
21    #[cfg(feature = "catch-all-fields")]
22    #[cfg_attr(docsrs, doc(cfg(feature = "catch-all-fields")))]
23    #[serde(flatten)]
24    pub other: serde_json::Map<String, Value>,
25}
26
27#[derive(Debug, Clone, Eq, PartialEq, Deserialize, Serialize)]
28#[serde(rename_all = "camelCase")]
29pub struct RabbitMqMessage {
30    pub basic_properties: RabbitMqBasicProperties,
31    #[serde(default)]
32    pub data: Option<String>,
33    pub redelivered: bool,
34    /// Catchall to catch any additional fields that were present but not explicitly defined by this struct.
35    /// Enabled with Cargo feature `catch-all-fields`.
36    /// If `catch-all-fields` is disabled, any additional fields that are present will be ignored.
37    #[cfg(feature = "catch-all-fields")]
38    #[cfg_attr(docsrs, doc(cfg(feature = "catch-all-fields")))]
39    #[serde(flatten)]
40    pub other: serde_json::Map<String, Value>,
41}
42
43#[derive(Debug, Clone, Eq, PartialEq, Deserialize, Serialize)]
44#[serde(rename_all = "camelCase")]
45pub struct RabbitMqBasicProperties<T1 = Value>
46where
47    T1: DeserializeOwned,
48    T1: Serialize,
49{
50    #[serde(default)]
51    pub content_type: Option<String>,
52    pub content_encoding: Option<String>,
53    /// Application or header exchange table
54    #[serde(deserialize_with = "deserialize_lambda_map")]
55    #[serde(default)]
56    #[serde(bound = "")]
57    pub headers: HashMap<String, T1>,
58    pub delivery_mode: u8,
59    pub priority: u8,
60    pub correlation_id: Option<String>,
61    pub reply_to: Option<String>,
62    #[serde(default)]
63    pub expiration: Option<String>,
64    pub message_id: Option<String>,
65    #[serde(default)]
66    pub timestamp: Option<String>,
67    pub type_: Option<String>,
68    #[serde(default)]
69    pub user_id: Option<String>,
70    pub app_id: Option<String>,
71    pub cluster_id: Option<String>,
72    pub body_size: u64,
73    /// Catchall to catch any additional fields that were present but not explicitly defined by this struct.
74    /// Enabled with Cargo feature `catch-all-fields`.
75    /// If `catch-all-fields` is disabled, any additional fields that are present will be ignored.
76    #[cfg(feature = "catch-all-fields")]
77    #[cfg_attr(docsrs, doc(cfg(feature = "catch-all-fields")))]
78    #[serde(flatten)]
79    pub other: serde_json::Map<String, Value>,
80}
81
82#[cfg(test)]
83mod test {
84    use super::*;
85
86    #[test]
87    #[cfg(feature = "rabbitmq")]
88    fn example_rabbitmq_event() {
89        let data = include_bytes!("../../fixtures/example-rabbitmq-event.json");
90        let parsed: RabbitMqEvent = serde_json::from_slice(data).unwrap();
91        let output: String = serde_json::to_string(&parsed).unwrap();
92        let reparsed: RabbitMqEvent = serde_json::from_slice(output.as_bytes()).unwrap();
93        assert_eq!(parsed, reparsed);
94    }
95}