A Spring Boot application integrating with RabbitMQ for message queuing, featuring REST endpoints for notifications and orders.
- Java 17+
- Maven
- Docker (for RabbitMQ)
-
Clone the repository:
git clone https://github.com/youssefGamalMohamed/spring-boot-mq.git cd spring-boot-mq
-
Build and run the application:
mvn clean install mvn spring-boot:run
-
Run RabbitMQ container:
docker run -d --name rabbitmq -p 5672:5672 -p 15672:15672 rabbitmq:management
-
Access RabbitMQ UI:
Open http://localhost:15672 and log in with:
- Username:
guest
- Password:
guest
- Username:
The application configuration is specified in src/main/resources/application.yml
:
spring:
application:
name: mq-examples
rabbitmq:
host: localhost
port: 5672
username: guest
password: guest
server:
port: 9090
logging:
level:
org.springframework.amqp: INFO
org.springframework.amqp.rabbit: INFO
org.springframework.amqp.rabbit.connection: INFO
rabbitmq:
queues-names:
order_inventory_service_queue: order_inventory_service_queue
notification_system_user1_queue: notification_system_user1_queue
notification_system_user2_queue: notification_system_user2_queue
exchange-names:
ecommerce_exchange: ecommerce_exchange
notification_topic_exchange: notification_topic_exchange
routing-keys:
order_inventory_service_routing_key: order_inventory_service_routing_key
notification_service_routing_default_key: notification_service_routing_default_key
-
Endpoint:
/api/v1/notifications
-
Method:
POST
-
Request Body:
NotificationDto
{ "title": "string", "content": "string" }
-
Description: Sends a notification message to the RabbitMQ notification queue.
-
Endpoint:
/api/v1/orders
-
Method:
POST
-
Request Body:
OrderDto
{ "cartItems": [ { "product": { "name": "string", "quantity": 0, "price": 0.0 }, "orderedQuantityFromProduct": 0 } ] }
-
Description: Sends an order message to the RabbitMQ order queue.
-
CartItem
@Data @Builder @AllArgsConstructor @NoArgsConstructor public class CartItem implements Serializable { private ProductDto product; private Integer orderedQuantityFromProduct; }
-
NotificationDto
@Data @AllArgsConstructor @Builder public class NotificationDto implements Serializable { private String title; private String content; }
-
ProductDto
@Data @Builder @AllArgsConstructor @NoArgsConstructor public class ProductDto implements Serializable { private String name; private Integer quantity; private Double price; }
-
OrderDto
@Data @Builder @AllArgsConstructor @NoArgsConstructor public class OrderDto implements Serializable { private Set<CartItem> cartItems; }