This repository is a hands-on example of asynchronous messaging using Java, Spring Boot (Spring AMQP), and RabbitMQ. It demonstrates a typical event-driven pipeline:
Producer → Exchange → Queue → Consumer
The project includes a Docker Compose setup that starts RabbitMQ and runs the Spring Boot application using the Maven Wrapper.
AsynchronousMessaging/
├── assets/
│ └── rabbitmq-architecture.jpg # Architecture diagram
├── src/
│ ├── main/
│ │ ├── java/ # Source code (producer/consumer/config)
│ │ └── resources/ # Spring configuration
│ └── test/ # Unit and integration tests
├── docker-compose.yml # Docker setup
├── pom.xml # Maven dependencies
└── README.md # This file- Java
- Spring Boot (Spring AMQP / RabbitMQ)
- RabbitMQ
- Maven (Maven Wrapper included)
- Publishing messages to RabbitMQ (producer)
- Consuming messages from RabbitMQ (consumer)
- Basic AMQP topology configuration (exchange / queue / binding)
- Running everything locally with Docker Compose
- Docker Engine + Docker Compose v2
- Linux is recommended for the provided Compose setup (see note below)
The included docker-compose.yml uses host networking as a workaround for some Docker/iptables configurations (where creating a Docker bridge network fails).
With host networking:
- containers share the host network stack
- ports are exposed directly on your machine
ports:mappings are not required (and are ignored by Docker)
Make sure these ports are free on your host:
- RabbitMQ AMQP: 5672
- RabbitMQ Management UI: 15672
- Spring Boot app: 8080 (configurable)
From the repository root:
docker compose updocker compose stopdocker compose down
RabbitMQ UI
URL: http://localhost:15672
username: guest
password: guestThe application connects to RabbitMQ using environment variables set in docker-compose.yml:
SPRING_RABBITMQ_HOST=localhost
SPRING_RABBITMQ_PORT=5672
SPRING_RABBITMQ_USERNAME=guest
SPRING_RABBITMQ_PASSWORD=guestThe app runs on:
SERVER_PORT=8080To change it, update SERVER_PORT in docker-compose.yml.
The exact topology is defined in the application configuration and/or Spring AMQP config classes.
To find it, check:
src/main/resources/application.ymlorapplication.properties- Configuration classes under
src/main/java/...(often named*Rabbit*Config/*Amqp*Config)
Once verified, document the values here:
- Exchange: YOUR_EXCHANGE_NAME
- Queue: YOUR_QUEUE_NAME
- Routing key: YOUR_ROUTING_KEY
How you publish depends on how the producer is implemented:
- REST endpoint (
@RestController) - Startup runner (
CommandLineRunner) - Service method invoked internally
Locate your controller in src/main/java/... and adjust the URL accordingly.
Example request template:
curl -X POST "http://localhost:8080/api/messages" \
-H "Content-Type: application/json" \
-d '{"message":"hello rabbit","timestamp":"2026-01-31T12:00:00Z"}'docker logs -f asyncmsg-appdocker logs -f asyncmsg-rabbitmqBecause host networking exposes ports on the host, you can get conflicts.
Check port usage:
sudo ss -lntp | egrep ':(5672|15672|8080)\b'Fix:
- Stop the service using the port, or
- Change
SERVER_PORTindocker-compose.yml
docker ps
docker logs -f asyncmsg-rabbitmq- Ensure RabbitMQ is healthy (Compose defines a healthcheck)
- Verify RabbitMQ is listening on 5672
- Check app logs:
docker logs -f asyncmsg-app
If you run RabbitMQ separately (local install or your own container), you can run the app directly.
./mvnw spring-boot:runmvnw.cmd spring-boot:runsrc/main/java– Source code (producer/consumer/config)src/main/resources– Spring configurationpom.xml– Maven dependencies
