This project demonstrates a simple Microservices architecture using Spring Boot and RabbitMQ. It implements a Producer-Consumer pattern where the Order Service publishes order events to a RabbitMQ queue, and a Consumer (within the same app for demonstration) processes them.
- Java 17
- Spring Boot 3.x
- Spring AMQP (RabbitMQ)
- Docker
- Lombok
- Java 17+ Installed
- Docker Installed
Before running the application, you must have RabbitMQ running. We use Docker for this.
docker run -d --name rabbitmq -p 5672:5672 -p 15672:15672 rabbitmq:3-management- Dashboard: http://localhost:15672 (User:
guest, Pass:guest)
./mvnw spring-boot:runThe application will start on port 8080.
- Build the JAR:
./mvnw clean package -DskipTests
- Build the Image:
docker build -t order-service . - Run the Container:
docker run -d -p 8080:8080 --name order-service --link rabbitmq:rabbitmq -e SPRING_RABBITMQ_HOST=rabbitmq order-service
Send a POST request to place an order. This will trigger the Producer to send a message and the Consumer to print it.
curl -X POST http://localhost:8080/order \
-H "Content-Type: application/json" \
-d '{"name": "Pizza", "quantity": 1, "price": 12.5}'Expected Output (Application Logs):
Message Received from Queue: Order(orderId=..., name=Pizza, quantity=1, price=12.5)
config/RabbitMQConfig: Configures the Exchange (order_exchange), Queue (order_queue), and Binding. Also defines the JSON MessageConverter.controller/OrderController: REST Controller that receives the HTTP request and publishes the message.consumer/OrderConsumer: Listens toorder_queueand processes messages.dto/Order: Data Transfer Object shared between Producer and Consumer.