Skip to content

Commit

Permalink
update readme (#15)
Browse files Browse the repository at this point in the history
* update readme

Update docs for usage of partitioned queues.

* fix readme formatting
  • Loading branch information
ChuckHend authored Aug 1, 2023
1 parent 78756df commit 1911426
Showing 1 changed file with 52 additions and 14 deletions.
66 changes: 52 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ A lightweight distributed message queue. Like [AWS SQS](https://aws.amazon.com/s
- Lightweight - Built with Rust and Postgres only
- Guaranteed "exactly once" delivery of messages consumer within a visibility timeout
- API parity with [AWS SQS](https://aws.amazon.com/sqs/) and [RSMQ](https://github.com/smrchy/rsmq)
- Messages stay in the queue until deleted
- Messages stay in the queue until explicitly deleted
- Messages can be archived, instead of deleted, for long-term retention and replayability
- Table (bloat) maintenance automated with [pg_partman](https://github.com/pgpartman/pg_partman)
- High performance operations with index-only scans.

## Table of Contents
- [Postgres Message Queue (PGMQ)](#postgres-message-queue-pgmq)
- [Features](#features)
Expand Down Expand Up @@ -61,18 +61,19 @@ CREATE EXTENSION pgmq CASCADE;
Every queue is its own table in Postgres. The table name is the queue name prefixed with `pgmq_`.
For example, `pgmq_my_queue` is the table for the queue `my_queue`.

Optionally, the `partition_interval` and `retention_interval` can be configured. See [Configuration](#configuration).
```sql
-- creates the queue

-- params
-- queue_name: text
-- partition_interval: text DEFAULT 'daily'::text
-- retention_interval: text DEFAULT '5 days'::text
SELECT pgmq_create('my_queue');
```

pgmq_create
```text
pgmq_create
-------------
(1 row)
```

### Send two messages
Expand All @@ -84,8 +85,9 @@ SELECT * from pgmq_send('my_queue', '{"foo": "bar1"}');
SELECT * from pgmq_send('my_queue', '{"foo": "bar2"}');
```

```sql
-- the message id is returned from the send function
The message id is returned from the send function

```text
pgmq_send
-----------
1
Expand All @@ -105,7 +107,9 @@ Read `2` message from the queue. Make them invisible for `30` seconds.

```sql
pgmq=# SELECT * from pgmq_read('my_queue', 30, 2);
```

```text
msg_id | read_ct | vt | enqueued_at | message
--------+---------+-------------------------------+-------------------------------+---------------
1 | 1 | 2023-02-07 04:56:00.650342-06 | 2023-02-07 04:54:51.530818-06 | {"foo":"bar1"}
Expand All @@ -116,6 +120,9 @@ If the queue is empty, or if all messages are currently invisible, no rows will

```sql
pgmq=# SELECT * from pgmq_read('my_queue', 30, 1);
```

```text
msg_id | read_ct | vt | enqueued_at | message
--------+---------+----+-------------+---------
```
Expand All @@ -125,46 +132,77 @@ pgmq=# SELECT * from pgmq_read('my_queue', 30, 1);
```sql
-- Read a message and immediately delete it from the queue. Returns `None` if the queue is empty.
pgmq=# SELECT * from pgmq_pop('my_queue');
```

```text
msg_id | read_ct | vt | enqueued_at | message
--------+---------+-------------------------------+-------------------------------+---------------
1 | 2 | 2023-02-07 04:56:00.650342-06 | 2023-02-07 04:54:51.530818-06 | {"foo":"bar1"}
```

### Archive a message

Archiving a message removes it from the queue, and inserts it to the archive table.

Archive message with msg_id=2

```sql
-- Archiving a message removes it from the queue, and inserts it to the archive table.
-- archive message with msg_id=2
pgmq=# SELECT * from pgmq_archive('my_queue', 2);
```

```text
pgmq_archive
--------------
t
(1 row)
```

```sql
pgmq=# SELECT * from pgmq_my_queue_archive;
```

```text
msg_id | read_ct | enqueued_at | deleted_at | vt | message
--------+---------+------------------------------+-------------------------------+-------------------------------+-----------------
2 | 1 | 2023-04-25 00:55:40.68417-05 | 2023-04-25 00:56:35.937594-05 | 2023-04-25 00:56:20.532012-05 | {"foo": "bar2"}```
```
### Delete a message
Send another message, so that we can delete it.
```sql
-- Delete a message id `3` from queue named `my_queue`.
pgmq=# SELECT * from pgmq_send('my_queue', '{"foo": "bar3"}');
```

```text
pgmq_send
-----------
3
(1 row)
```

Delete tha message with id `3` from queue named `my_queue`.

```sql
pgmq=# SELECT pgmq_delete('my_queue', 3);
pgmq_delete
```

```text
pgmq_delete
-------------
t
(1 row)
```

# Configuration

## Partitioned Queues

`pgmq` queue tables are partitioned by default. [pg_partman](https://github.com/pgpartman/pg_partman/)
`pgmq` queue tables can be created as a paritioned table by using pgmq_create_partitioned(). [pg_partman](https://github.com/pgpartman/pg_partman/)
handles all maintenance of queue tables. This includes creating new partitions and dropping old partitions.

Partitions behavior is configured at the time queues are created, via `pgmq_create()`. This function has a three parameters:
Partitions behavior is configured at the time queues are created, via `pgmq_create_partitioned()`. This function has a three parameters:

`queue_name: text` : The name of the queue. Queues are Postgres tables prepended with `pgmq_`. For example, `pgmq_my_queue`.

Expand Down

0 comments on commit 1911426

Please sign in to comment.