RabbitMQ
Fiber and RabbitMQ example
Description
This example demonstrates how to integrate RabbitMQ with a Fiber HTTP server. The API exposes a /send endpoint that publishes messages to a RabbitMQ queue. A separate worker process consumes messages from the queue and prints them to the console.
How it works

- The Fiber API server connects to RabbitMQ and exposes
GET /send?msg=<text>. - Each request publishes the
msgquery parameter as a message to theTestQueuequeue. - The worker process subscribes to
TestQueueand logs received messages.
Prerequisites
- Go 1.27+
- Docker and Docker Compose
Environment variables
| Variable | Default | Description |
|---|---|---|
RABBITMQ_URL | amqp://user:password@localhost:5672/ | RabbitMQ connection URL |
Setup
Option A: Docker Compose (recommended)
Start all services (RabbitMQ, worker, API) with a single command:
docker compose up --buildThe Dockerfiles start with FROM --platform=$BUILDPLATFORM, which needs BuildKit, the default builder of Docker Engine 23 and later and of Docker Desktop. With an older Docker Engine set DOCKER_BUILDKIT=1, and with docker-compose v1 also COMPOSE_DOCKER_CLI_BUILD=1.
Option B: Manual setup
- Start RabbitMQ:
make docker.network
make docker.rabbitmqWait ~30 seconds for RabbitMQ to be ready.
Start the worker (in a separate terminal):
make docker.worker- Run the API server:
make run
# or
RABBITMQ_URL=amqp://user:password@localhost:5672/ go run main.goEndpoints
GET /send
Publishes a message to the TestQueue RabbitMQ queue.
| Parameter | Type | Required | Description |
|---|---|---|---|
msg | string | yes | Message to publish |
Success response 200 OK:
{"status": "message sent"}Error response 400 Bad Request:
{"error": "msg parameter required"}curl examples
Send a message:
curl "http://127.0.0.1:3000/send?msg=Hello%20World"Missing parameter (returns 400):
curl "http://127.0.0.1:3000/send"Worker output
When a message is received, the worker prints:
2021/03/27 16:32:35 Successfully connected to RabbitMQ instance
2021/03/27 16:32:35 [*] - Waiting for messages
2021/03/27 16:32:35 [*] - Run Fiber API server and go to http://127.0.0.1:3000/send?msg=<YOUR TEXT HERE>
2021/03/27 16:33:24 Received message: Hello WorldRabbitMQ management dashboard
The RabbitMQ management UI is available at http://localhost:15672 (default credentials: user / password).
