pgqrs
A PostgreSQL-backed job queue for Rust applications.
Features
- Lightweight: No servers to operate. Directly use
pgqrsas a library in your Rust applications. - Compatible with Connection Poolers: Use with pgBouncer or pgcat to scale connections.
- Efficient: Uses PostgreSQL's
SKIP LOCKEDfor concurrent job fetching. - Exactly Once Delivery: Guarantees exactly-once delivery within a time range specified by time limit.
- Message Archiving: Built-in archiving system for audit trails and historical data retention.
Example
Producer
use Producer;
use Value;
/// Enqueue a payload to the queue
async
Consumer
use ;
use Duration;
/// Poll for jobs from the queue and print them as they arrive
async
Quickstart
Install the binary
Start a Postgres DB or get the DSN of an existing db.
You'll need a PostgreSQL database to use pgqrs. Here are your options:
Option 1: Using Docker (Recommended for development)
# Start a PostgreSQL container
# Your DSN will be:
# postgresql://postgres:postgres@localhost:5432/postgres
Option 2: Using an existing PostgreSQL database
Get your database connection string (DSN) in this format:
postgresql://username:password@hostname:port/database
Option 3: Using a cloud PostgreSQL service
- AWS RDS: Get the connection string from the RDS console
- Google Cloud SQL: Get the connection string from the Cloud Console
- Azure Database: Get the connection string from the Azure portal
- Heroku Postgres: Use the
DATABASE_URLfrom your Heroku config
Configure pgqrs
Set your database connection using one of these methods (in order of priority):
# Method 1: Command line argument (highest priority)
# Method 2: Environment variable
Create a pgqrs.yaml file:
dsn: "postgresql://postgres:postgres@localhost:5432/postgres"
Then run:
# Method 3: Use a yaml config file.
Install the pgqrs schema
pgqrs requires a few tables to store metadata. It creates these tables as well as queue tables in the specified schema.
Important: You must create the schema before running pgqrs install.
Step 1: Create the schema
Connect to your PostgreSQL database and create the schema:
-- For default 'public' schema (no action needed)
-- For custom schema:
;
Step 2: Install pgqrs
Once you have your database configured and schema created, install the pgqrs schema:
# Install in default 'public' schema
# Install in custom schema
# Verify the installation
# Or verify custom schema
Test queue commands from the CLI
Items can be enqueued or dequeued using the CLI. This option is only available for testing or experiments.
# Create a test queue
# Send a message to the queue
# Send a delayed message (available after 30 seconds)
# Read and immediately consume one message
# Delete a specific message by ID
License
Licensed under either of:
- Apache License, Version 2.0
- MIT license
at your option.