docs.rs failed to build pgx_pgmq-0.0.4
Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
Postgres Message Queue
A lightweight message queue extension for Postgres. Provides similar experience to AWS SQS and Redis Simple Message Queue, but on Postgres.
Installation
TODO
docker run ...
Python Examples
Connect to postgres
=
Create and list queues
# create a queue
=
# list queues
=
=
=
'### Queues ###'
{'created_at': datetime.datetime(2023, 2, 7, 2, 5, 39, 946356, tzinfo=datetime.timezone(datetime.timedelta(days=-1, seconds=64800))),
'queue_name': 'myqueue'}
Send a message to the queue
# send a message
=
=
=
=
'### Message ID ###'
{'msg_id': 1}
Read a message from the queue
# read a message, make it unavailable to be read again for 5 seconds
=
=
=
'### Read Message ###'
{'enqueued_at': datetime.datetime(2023, 2, 7, 2, 51, 50, 468837, tzinfo=datetime.timezone(datetime.timedelta(days=-1, seconds=64800))),
'message': {'myqueue': 42},
'msg_id': 1,
'read_ct': 1,
'vt': datetime.datetime(2023, 2, 7, 16, 9, 4, 826669, tzinfo=datetime.timezone(datetime.timedelta(days=-1, seconds=64800)))}
Delete a message from the queue
# delete a message
=
=
=
'### Message Deleted ###'
{'pgmq_delete': True}
SQL Examples
CREATE EXTENSION pgmq;
Creating a queue
SELECT pgmq_create('my_queue');
pgmq_create
-------------
Send a message
pgmq=# SELECT * from pgmq_send('my_queue', '{"foo": "bar"}');
pgmq_send
--------------
1
Read a message
Reads a single message from the queue. Make it invisible for 30 seconds.
pgmq=# SELECT * from pgmq_read('my_queue', 30);
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":"bar"}
If the queue is empty, or if all messages are currently invisible, no rows will be returned.
pgx_pgmq=# SELECT * from pgmq_read('my_queue', 30);
msg_id | read_ct | vt | enqueued_at | message
--------+---------+----+-------------+---------
Pop a message
Read a message and immediately delete it from the queue. Returns None
if the queue is empty.
pgmq=# SELECT * from pgmq_pop('my_queue');
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":"bar"}
Archive a message
Archiving a message removes it from the queue, and inserts it to the archive table. TODO:
Delete a message
Delete a message with id 1
from queue named my_queue
.
pgmq=# select pgmq_delete('my_queue', 1);
pgmq_delete
-------------
t
Development
Setup pgx
.
Then, clone this repo and change into this directory.
Run the dev environment
Packaging
Run this script to package into a .deb
file, which can be installed on Ubuntu.
/bin/bash build-extension.sh