pgmq-rs

Crates.iopgmq-rs
lib.rspgmq-rs
version0.0.1-alpha
sourcesrc
created_at2023-01-05 16:08:35.707982
updated_at2023-01-05 16:08:35.707982
descriptionA Rust client for Postgres Message Queues
homepagehttps://www.coredb.io
repository
max_upload_size
id751637
size49,784
Adam Hendel (ChuckHend)

documentation

https://github.com/CoreDB-io

README

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@0.0.0.0:5432".to_owned(),
    vt: 30,
    delay: 0,
};

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

Create the queue

queue.create().await?;

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;
Commit count: 0

cargo fmt