Simple example showing how to send and receive messages with RabbitMQ using Go and the github.com/rabbitmq/amqp091-go client.
Files in this repo:
Quick overview:
- Sender:
send.mainsends a single message ("Hello World!") to thehelloqueue usingPublishWithcontext. - Receiver:
receive.mainconsumes messages from thehelloqueue and logs them usingConsume.
Requirements
- Go (see go.mod)
- Docker & Docker Compose
Run locally with Docker Compose
- Start RabbitMQ:
docker-compose up -dSee configuration in docker-compose.yml. 2. Wait until RabbitMQ is healthy (healthcheck may take a few seconds):
docker-compose logs -f rabbitmqRun the receiver (keep this running in one terminal)
go run ./receiveor
go run [receive.go](receive/receive.go)This runs the code in receive/main and will print received messages.
Run the sender (in another terminal)
go run ./sendor
go run [send.go](send/send.go)This runs the code in send/main and sends a single message.
Build binaries
go build -o bin/receive ./receive
go build -o bin/send ./sendTroubleshooting
- Connection refused: ensure RabbitMQ is running and ports in docker-compose.yml (5672, 15672) are available.
- Check Docker container status:
docker ps
docker-compose logs rabbitmqIf Go modules are missing dependencies, run:
go mod tidySee go.mod.