pgmb

pgmb : A simple PostgreSQL Message Broker system

Overview

IDExtensionPackageVersionCategoryLicenseLanguage
2870
pgmb
pgmb
1.0.0
FEAT
PostgreSQL
SQL
AttributeHas BinaryHas LibraryNeed LoadHas DDLRelocatableTrusted
----d--
No
No
No
Yes
no
no
Relationships
Schemaspgmb
Requires
pg_cron
http
See Also
pgmq
pgq
pg_task
pg_cron
pg_background
pg_later
pg_net
kafka_fdw

Packages

TypeRepoVersionPG Major CompatibilityPackage PatternDependencies
EXT
PIGSTY
1.0.0
18
17
16
15
14
pgmbpg_cron, http
RPM
PIGSTY
1.0.0
18
17
16
15
14
pgmb_$vpg_cron_$v, pg_http_$v
DEB
PIGSTY
1.0.0
18
17
16
15
14
postgresql-$v-pgmbpostgresql-$v-cron, postgresql-$v-http
Linux / PGPG18PG17PG16PG15PG14
el8.x86_64
PIGSTY 1.0.0
PIGSTY 1.0.0
PIGSTY 1.0.0
PIGSTY 1.0.0
PIGSTY 1.0.0
el8.aarch64
PIGSTY 1.0.0
PIGSTY 1.0.0
PIGSTY 1.0.0
PIGSTY 1.0.0
PIGSTY 1.0.0
el9.x86_64
PIGSTY 1.0.0
PIGSTY 1.0.0
PIGSTY 1.0.0
PIGSTY 1.0.0
PIGSTY 1.0.0
el9.aarch64
PIGSTY 1.0.0
PIGSTY 1.0.0
PIGSTY 1.0.0
PIGSTY 1.0.0
PIGSTY 1.0.0
el10.x86_64
PIGSTY 1.0.0
PIGSTY 1.0.0
PIGSTY 1.0.0
PIGSTY 1.0.0
PIGSTY 1.0.0
el10.aarch64
PIGSTY 1.0.0
PIGSTY 1.0.0
PIGSTY 1.0.0
PIGSTY 1.0.0
PIGSTY 1.0.0
d12.x86_64
PIGSTY 1.0.0
PIGSTY 1.0.0
PIGSTY 1.0.0
PIGSTY 1.0.0
PIGSTY 1.0.0
d12.aarch64
PIGSTY 1.0.0
PIGSTY 1.0.0
PIGSTY 1.0.0
PIGSTY 1.0.0
PIGSTY 1.0.0
d13.x86_64
PIGSTY 1.0.0
PIGSTY 1.0.0
PIGSTY 1.0.0
PIGSTY 1.0.0
PIGSTY 1.0.0
d13.aarch64
PIGSTY 1.0.0
PIGSTY 1.0.0
PIGSTY 1.0.0
PIGSTY 1.0.0
PIGSTY 1.0.0
u22.x86_64
PIGSTY 1.0.0
PIGSTY 1.0.0
PIGSTY 1.0.0
PIGSTY 1.0.0
PIGSTY 1.0.0
u22.aarch64
PIGSTY 1.0.0
PIGSTY 1.0.0
PIGSTY 1.0.0
PIGSTY 1.0.0
PIGSTY 1.0.0
u24.x86_64
PIGSTY 1.0.0
PIGSTY 1.0.0
PIGSTY 1.0.0
PIGSTY 1.0.0
PIGSTY 1.0.0
u24.aarch64
PIGSTY 1.0.0
PIGSTY 1.0.0
PIGSTY 1.0.0
PIGSTY 1.0.0
PIGSTY 1.0.0

Source

pig build pkg pgmb;		# build rpm/deb

Install

Make sure PGDG and PIGSTY repo available:

pig repo add pgsql -u   # add both repo and update cache

Install this extension with pig:

pig install pgmb;		# install via package name, for the active PG version

pig install pgmb -v 18;   # install for PG 18
pig install pgmb -v 17;   # install for PG 17
pig install pgmb -v 16;   # install for PG 16
pig install pgmb -v 15;   # install for PG 15
pig install pgmb -v 14;   # install for PG 14

Create this extension with:

CREATE EXTENSION pgmb CASCADE; -- requires pg_cron, http

Usage

pgmb: A lightweight message broker system built inside PostgreSQL

The pgmb extension provides an in-database message broker with HTTP-based worker dispatch, automatic retries, dead letter queues, and pattern-based routing.

CREATE EXTENSION pgmb;  -- requires pg_cron and http extensions

Register a Worker

SELECT pgmb.worker(
    'order_processor',                     -- worker name
    'http://localhost:8080/process',       -- endpoint URL
    100                                    -- requests per second limit
);
-- Returns: worker UUID

Create a Queue

SELECT pgmb.create(
    'order_queue',                         -- queue name
    'order.*',                             -- binding key pattern (supports * wildcard)
    5,                                     -- max retries
    '550e8400-e29b-41d4-a716-446655440000' -- worker UUID
);
-- Returns: queue UUID

Send Messages

-- Simple message
SELECT pgmb.send(
    gen_random_uuid(),
    'order.created',
    '{"order_id": 123, "amount": 45.67}'::jsonb
);

-- With custom headers
SELECT pgmb.send(
    gen_random_uuid(),
    'order.created',
    '{"order_id": 123}'::jsonb,
    '{"source": "web", "priority": "high"}'::jsonb
);

-- Delayed message (by timestamp or seconds)
SELECT pgmb.send(
    gen_random_uuid(),
    'order.created',
    '{"order_id": 123}'::jsonb,
    '{}'::jsonb,
    now() + interval '10 minutes'
);

API Reference

FunctionDescription
pgmb.worker(name, endpoint, rps)Register an HTTP worker endpoint
pgmb.create(name, binding_key, max_retries, worker_id)Create a queue with routing pattern
pgmb.send(id, routing_key, body)Send a message
pgmb.send(id, routing_key, body, headers)Send a message with headers
pgmb.send(id, routing_key, body, headers, delay)Send a delayed message

How It Works

  1. Messages are inserted into pgmb.messages via pgmb.send()
  2. A trigger routes messages to matching queues based on routing key patterns
  3. pg_cron dispatches messages via HTTP POST to worker endpoints every second
  4. Failed messages are retried; after max retries they move to a dead letter queue

Monitoring

SELECT * FROM pgmb.workers;
SELECT * FROM pgmb.queues;
SELECT COUNT(*) FROM pgmb.order_queue WHERE acknoledge = false;
SELECT * FROM pgmb.order_dead_letter_queue;
Last updated on