-
Notifications
You must be signed in to change notification settings - Fork 0
RabbitMQ
Beau Barker edited this page Jun 30, 2025
·
3 revisions
How to publish to RabbitMQ from Postgres.
git clone https://github.com/omniti-labs/pg_amqp postgres/pg_amqp
Edit postgres/Dockerfile
to build and install the extension:
RUN apt-get update && apt-get install -y \
build-essential \
postgresql-server-dev-17
# pg_amqp - Used by api schema
COPY ./pg_amqp /pg_amqp
WORKDIR /pg_amqp
RUN make
RUN make install
WORKDIR /var/lib/postgresql
You may need to fix "implicit int" errors in pg_amqp, which were reported here, and fixed but not yet merged.
Then rebuild:
docker compose build postgres
Add this to a migration file like 01-extensions.sql
:
-- amqp extension for rabbitmq connection
create extension amqp;
⚠️ Do not wrap this file in aBEGIN/COMMIT
block —create extension
is non-transactional.
Add to a migration file, e.g. 10-create_api_schema.sql
.
-- 10-create_api_schema.sql
begin;
create table api.task (
id serial primary key,
name text not null
);
create function api.task_updated() returns void
language plpgsql as $$
begin
perform amqp.publish(1, 'amq.topic', 'tasks', json_build_object('event', 'task_updated', 'command', command)::text);
end;
$$;
create trigger task_updated
before update on api.task
for each row execute procedure api.task_updated();
commit;
Once your migrations are ready:
bin/postgres migrate
SuperStack will execute the new migration files, skipping those already applied.
Add to compose.yaml
:
services:
rabbitmq:
image: rabbitmq:3
ports:
- 5672:5672
environment:
RABBITMQ_SERVER_ADDITIONAL_ERL_ARGS: "-rabbit channel_max 0"