pgmb
pgmb
pgmb : A simple PostgreSQL Message Broker system
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 2870 | pgmb
|
pgmb
|
1.0.0 |
FEAT
|
PostgreSQL
|
SQL
|
| Attribute | Has Binary | Has Library | Need Load | Has DDL | Relocatable | Trusted |
|---|---|---|---|---|---|---|
----d--
|
No
|
No
|
No
|
Yes
|
no
|
no
|
| Relationships | |
|---|---|
| Schemas | pgmb |
| Requires | pg_cron
http
|
| See Also | pgmq
pgq
pg_task
pg_cron
pg_background
pg_later
pg_net
kafka_fdw
|
Packages
| Type | Repo | Version | PG Major Compatibility | Package Pattern | Dependencies |
|---|---|---|---|---|---|
| EXT | PIGSTY
|
1.0.0 |
18
17
16
15
14
|
pgmb |
pg_cron, http |
| RPM | PIGSTY
|
1.0.0 |
18
17
16
15
14
|
pgmb_$v |
pg_cron_$v, pg_http_$v |
| DEB | PIGSTY
|
1.0.0 |
18
17
16
15
14
|
postgresql-$v-pgmb |
postgresql-$v-cron, postgresql-$v-http |
| Linux / PG | PG18 | PG17 | PG16 | PG15 | PG14 |
|---|---|---|---|---|---|
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/debInstall
Make sure PGDG and PIGSTY repo available:
pig repo add pgsql -u # add both repo and update cacheInstall 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 14Create this extension with:
CREATE EXTENSION pgmb CASCADE; -- requires pg_cron, httpUsage
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 extensionsRegister a Worker
SELECT pgmb.worker(
'order_processor', -- worker name
'http://localhost:8080/process', -- endpoint URL
100 -- requests per second limit
);
-- Returns: worker UUIDCreate 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 UUIDSend 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
| Function | Description |
|---|---|
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
- Messages are inserted into
pgmb.messagesviapgmb.send() - A trigger routes messages to matching queues based on routing key patterns
pg_crondispatches messages via HTTP POST to worker endpoints every second- 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