#messaging #queues #postgres

yanked pgmq-rs

A Rust client for Postgres Message Queues

0.0.1-alpha Jan 5, 2023

#5 in #queues

MIT license

221 lines

Postgres Message Queue

Start any PG instance

docker run -d --name postgres -e POSTGRES_PASSWORD=postgres -p 5432:5432 postgres

Initialize a queue connection

use pgmq_rs::{Message, PGMQueue, PGMQueueConfig};

let qconfig = PGMQueueConfig {
    queue_name: "myqueue".to_owned(),
    url: "postgres://postgres:postgres@".to_owned(),
    vt: 30,
    delay: 0,

let queue: PGMQueue = qconfig.init().await;

Create the queue


Pusblish a message

let msg = serde_json::json!({
    "foo": "bar"
let msg_id = queue.enqueue(&msg).await;

Read a message

No messages are returned when the queue is empty or all messages are invisible.

Reading a message will make it invisible for the duration of the visibility timeout (vt).

let read_msg: Message = queue.read().await.unwrap();

Delete a message

Remove the message from the queue when you are done with it.

let deleted = queue.delete(&read_msg.msg_id).await;


~895K SLoC