azure_functions/event_hub/
system_properties.rs

1use crate::util::deserialize_datetime;
2use chrono::{DateTime, Utc};
3use serde::{Deserialize, Serialize};
4
5/// Represents properties that are set by the Event Hubs service.
6#[derive(Debug, Serialize, Deserialize)]
7#[serde(rename_all = "PascalCase")]
8pub struct SystemProperties {
9    /// The logical sequence number of the event within the partition stream of the Event Hub.
10    pub sequence_number: i64,
11    /// The data relative to the Event Hub partition stream.
12    pub offset: String,
13    /// The partition key of the corresponding partition.
14    pub partition_key: Option<String>,
15    /// The enqueuing time of the message time in UTC.
16    #[serde(rename = "EnqueuedTimeUtc", deserialize_with = "deserialize_datetime")]
17    pub enqueued_time: DateTime<Utc>,
18}
19
20#[cfg(test)]
21mod tests {
22    use super::*;
23    use serde_json::from_str;
24
25    #[test]
26    fn it_deserializes_from_json() {
27        const JSON: &'static str = r#"{"SequenceNumber":3,"Offset":"152","PartitionKey":null,"EnqueuedTimeUtc":"2019-02-22T04:43:55.305Z"}"#;
28
29        let properties: SystemProperties =
30            from_str(JSON).expect("failed to parse system properties JSON data");
31        assert_eq!(properties.sequence_number, 3);
32        assert_eq!(properties.offset, "152");
33        assert_eq!(properties.partition_key, None);
34        assert_eq!(
35            properties.enqueued_time.to_rfc3339(),
36            "2019-02-22T04:43:55.305+00:00"
37        );
38    }
39}