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.21+
- 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 --build
Option B: Manual setup
- Start RabbitMQ:
make docker.network
make docker.rabbitmq
-
Wait ~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.go
Endpoints
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 World
RabbitMQ management dashboard
The RabbitMQ management UI is available at http://localhost:15672 (default credentials: user / password).
