amqp
pg_amqp · Publish messages to AMQP brokers from PostgreSQL
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 100011 | amqp | pg_amqp | 0.4.2 | ETL | BSD-3-Clause | C |
PostgreSQL · 10, 11, 12, 13, 14, 15, 16, 17, 18
Usage
Sources:
amqp lets a PostgreSQL backend publish messages directly to an AMQP broker. It is useful for simple database-triggered notifications, but publishing is an external side effect and is not rolled back with the surrounding database transaction.
Core Workflow
Add pg_amqp to shared_preload_libraries, restart PostgreSQL, create the extension, and insert the broker host, port, user, and password into amqp.broker using the table definition shipped by the installed version. Then publish with the returned broker ID:
The final four amqp.publish arguments are optional message properties: delivery mode, content type, reply-to, and correlation ID. Delivery mode 1 is non-persistent and 2 requests persistent delivery; broker durability and consumer acknowledgement still determine end-to-end guarantees.
Important Objects
amqp.brokerstores broker connection details, including credentials.amqp.publishsends a message to an exchange with a routing key and payload.amqp.disconnectcloses the current backend’s connection for one broker; backend termination closes its remaining broker connections.
Operational Notes
Restrict all privileges on amqp.broker and on publish functions, and avoid exposing credentials through dumps, replicas, logs, or broad read roles. Network calls execute in database backends, so broker latency or failure can extend SQL latency and consume connections.
Do not use a successful SQL commit as proof that a message was delivered exactly once. Design consumers to be idempotent, include a durable application identifier, and use an outbox worker when atomic database-state/message coordination is required. The upstream project and API are old; compatibility, TLS/authentication support, reconnect behavior, and failure semantics need direct testing against the chosen broker and PostgreSQL release.