Skip to main content

pgmq/
types.rs

1use serde::Deserialize;
2use sqlx::types::chrono::{DateTime, Utc};
3use std::time::Duration;
4
5use sqlx::FromRow;
6
7pub const VT_DEFAULT: i32 = 30;
8pub const READ_LIMIT_DEFAULT: i32 = 1;
9pub const POLL_TIMEOUT_DEFAULT: Duration = Duration::from_secs(5);
10pub const POLL_INTERVAL_DEFAULT: Duration = Duration::from_millis(250);
11
12use chrono::serde::ts_seconds::deserialize as from_ts;
13
14pub const QUEUE_PREFIX: &str = r#"q"#;
15pub const ARCHIVE_PREFIX: &str = r#"a"#;
16pub const PGMQ_SCHEMA: &str = "pgmq";
17
18pub struct PGMQueueMeta {
19    pub queue_name: String,
20    pub is_partitioned: bool,
21    pub created_at: DateTime<Utc>,
22}
23
24/// Message struct received from the queue
25///
26/// It is an "envelope" for the message that is stored in the queue.
27/// It contains both the message body but also metadata about the message.
28#[derive(Clone, Debug, Deserialize, FromRow)]
29pub struct Message<T = serde_json::Value> {
30    /// unique identifier for the message
31    pub msg_id: i64,
32    #[serde(deserialize_with = "from_ts")]
33    /// "visibility time". The UTC timestamp at which the message will be available for reading again.
34    pub vt: chrono::DateTime<Utc>,
35    /// UTC timestamp that the message was sent to the queue
36    pub enqueued_at: chrono::DateTime<Utc>,
37    /// The number of times the message has been read. Increments on read.
38    pub read_ct: i32,
39    /// The message body.
40    pub message: T,
41}