How felipecesargomes/rabbitmq-fanout-spring works
Project type and purpose
• This is a distributed, event-driven microservices system built with Spring Boot and RabbitMQ in a fanout pattern.
• It consists of three independent services (pedidos-api, notification, worker) that communicate via a RabbitMQ exchange.
Main components
a. pedidos-api Service (Producer)
• Spring Boot REST API
• Publishes order messages to a RabbitMQ fanout exchange.
b. RabbitMQ (Message Broker)
• A fanout Exchange
• Two Bound Queues (one for notification, one for worker)
c. notification Service (Consumer #1)
• Listens on its queue
• Processes orders by sending emails via MailHog
d. worker Service (Consumer #2)
• Listens on its queue
• Persists order data to a database (JPA repositories)
e. External Services/Tools
• MailHog (SMTP server for email testing)
• (Optional) Relational Database for the worker service
Relationships and Data Flows
• Client → HTTP POST /orders → pedidos-api
• pedidos-api → publish message to FanoutExchange
• FanoutExchange → broadcast message to both queues
• notification.queue → notification Service consumes → EmailService → MailHog
• worker.queue → worker Service consumes → JPA Repositories → Database
Architectural Patterns & Principles
• Microservices: each service is packaged separately (its own pom.xml, Docker config).
• Event-Driven: loose coupling via RabbitMQ; producer doesn’t know consumers.
• Fanout Exchange: one-to-many broadcast semantics.
• Spring AMQP: RabbitMQConfig classes in each module.
• Separation of Concerns:
• pedidos-api: API layer + messaging
• notification: messaging + email
• worker: messaging + persistence
Technologies & Frameworks
• Java 11+ / Spring Boot
• Spring AMQP (RabbitMQConfig)
• Maven (build tool)
• RabbitMQ (broker)
• MailHog (email)
• Spring Data JPA (worker persistence)
• Docker-Compose (defines RabbitMQ, MailHog, maybe database)