Skip to content

About

Event-driven server in Gleam: RabbitMQ consumer/producer with Docker setup and tests

Resources

Stars

0 stars

Watchers

1 watching

Forks

Repository files navigation

gleam_event_driven

Event-driven backend written in Gleam: an HTTP API and two RabbitMQ consumers running as separate Erlang processes, backed by PostgreSQL.

Built for a code challenge, and mostly an excuse to find out what the BEAM gives you when the language on top is typed.

Architecture

HTTP (Wisp/Elli, :3000) ──> handlers ──> repositories ──> PostgreSQL
                                 │
RabbitMQ topics ──> "users" ─────┤  one Erlang process per queue,
                └─> "transactions"   started at boot and listening

src/server.gleam declares both queues, binds them to their topics, spawns a process per queue with process.start, and only then hands the port over to Elli. Consumers and the API live in the same supervision tree.

Why there is Elixir inside

Gleam had no AMQP client, so rabbitmq_client/ is a small Elixir library wrapping the amqp package, called from Gleam through @external(erlang, "Elixir.RabbitMQClient", ...) in src/rmq.gleam. Same BEAM, two languages, zero serialization between them.

Layout

Path What it is
src/server.gleam Entry point: declares queues and topics, spawns consumers, starts the HTTP server
src/rmq.gleam Gleam bindings to the Elixir AMQP client
src/app/routes, src/app/handlers HTTP routing and handlers
src/db/ Config, migrations and repositories (gleam_pgo)
rabbitmq_client/ Elixir library wrapping amqp, built with Mix
docker-compose.yml RabbitMQ with the management UI, PostgreSQL and the challenge service
docs/ User and transaction flow diagrams

Running

docker compose up -d   # RabbitMQ (5672, UI on 15672) and PostgreSQL
sh script.sh           # build and run the server on :3000

Stack

Gleam · Erlang/OTP · Elixir · Wisp · Elli · RabbitMQ (AMQP) · PostgreSQL · Docker Compose

About

Event-driven server in Gleam: RabbitMQ consumer/producer with Docker setup and tests

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages