bash
docker run -d --name postgres -e POSTGRES_PASSWORD=postgres -p 5432:5432 postgres
```rust use pgmq::{Message, PGMQueue};
let queue: PGMQueue = PGMQueue::new("postgres://postgres:postgres@0.0.0.0:5432".to_owned()).await;
```
rust
let myqueue = "myqueue".to_owned();
queue.create(&myqueue).await?;
queue.enqueue()
can be passed any type that implements serde::Serialize
. This means you can prepare your messages as JSON or as a struct.
rust
let msg = serde_json::json!({
"foo": "bar"
});
let msg_id = queue.enqueue(&myqueue, &msg).await;
```rust use serde::{Serialize, Deserialize};
struct MyMessage { foo: String, } let msg = MyMessage { foo: "bar".toowned(), }; let msgid: i64 = queue.enqueue(&myqueue, &msg).await; ```
Reading a message will make it invisible for the duration of the visibility timeout (vt).
No messages are returned when the queue is empty or all messages are invisible.
Messages can be parsed as JSON or as into a struct. queue.read()
returns an Option<Message<T>>
where T
is the type of the message on the queue. It can be parsed as JSON or as a struct.
Note that when parsing into a struct
, the application will panic if the message cannot be parsed as the type specified. For example, if the message expected is MyMessage{foo: "bar"}
but{"hello": "world"}
is received, the application will panic.
```rust use serde_json::Value;
let vt: u32 = 30;
let read_msg: Message
Reading a message will make it invisible for the duration of the visibility timeout (vt).
No messages are returned when the queue is empty or all messages are invisible. ```rust use serde_json::Value;
let vt: u32 = 30;
let read_msg: Message
Remove the message from the queue when you are done with it.
rust
let deleted = queue.delete(&read_msg.msg_id).await;