🇺🇸 English | 🇧🇷 Português
A hands-on project that demonstrates an event-driven microservices approach using RabbitMQ and pure Java (no Spring).
Instead of REST calls, services communicate asynchronously through RabbitMQ exchanges + routing keys, highlighting the fundamentals of AMQP messaging, loose coupling, and message filtering.
- MSReserva — reservation menu (publishes reservation events + receives notifications)
- MSPagamento — consumes reservations, simulates payment decision, digitally signs the result
- MSBilhete — verifies payment signature and issues tickets
- MSMarketing — publishes promotions by destination
- AssinantePromocoes — dynamic subscriber (bind/unbind routing keys at runtime)
Note: all services are in a single Maven module for simplicity (multiple
mainclasses). The runtime behavior simulates microservices.
- MSReserva publishes a reservation event to
EXGwith routing keyvermelho - MSPagamento consumes
vermelho, randomly approves/rejects payment, signs the message, and publishes to:verde(approved) orazul(rejected)
- MSBilhete consumes
verde/azul- when approved, verifies the signature and publishes a ticket notification to
amarelo
- when approved, verifies the signature and publishes a ticket notification to
- MSReserva consumes
verde,azul, andamareloand stores notifications in an in-memory queue
- MSMarketing publishes promotions using routing keys:
rio,salvador,manaus - AssinantePromocoes creates an exclusive auto-delete queue and binds keys based on the user menu
| Purpose | Queue | Routing key |
|---|---|---|
| Reservation created → MSPagamento | mspagamento_reserva_criada |
vermelho |
| Payment approved → MSReserva | pagamento-aprovado |
verde |
| Payment rejected → MSReserva | pagamento-recusado |
azul |
| Ticket issued → MSReserva | bilhete-emitido |
amarelo |
| Payment approved → MSBilhete | msbilhete_pagamento_aprovado |
verde |
| Payment rejected → MSBilhete | msbilhete_pagamento_recusado |
azul |
| Purpose | Queue | Routing key |
|---|---|---|
| Promotions subscriber | auto-generated (exclusive) | rio, salvador, manaus |
Payment events are published as:
<text>|<base64_signature>
Example:
Pagamento da reserva RESERVA-0001 aprovado|MEU...BASE64...==
- Signing algorithm:
SHA256withDSA MSPagamentosigns (private key)MSReservaandMSBilheteverify (public key)
- Java 8+ (project is configured for Java 8 in
pom.xml) - Maven 3+
- RabbitMQ running locally on
localhost:5672
Optional (recommended):
- RabbitMQ Management UI (
15672)
docker run --rm -it \
-p 5672:5672 -p 15672:15672 \
rabbitmq:3-managementManagement UI: http://localhost:15672 (default: guest/guest)
Start RabbitMQ and keep the default ports.
The key loader uses a fixed Windows path in cript/KeyReaderExample.java:
C:\Users\Afonso\Desktop\keys
You have two options:
- Create keys in that folder (Windows), or
- Edit the constant
DIRECTORY_PATHto point to your machine.
To generate keys, run:
cript.KeyGeneratorExample
It will create:
private.keypublic.key
Tip: don’t commit your
private.keyto Git.
You can run each service from your IDE (multiple run configurations) or from the terminal.
mvn -q -DskipTests package- MSPagamento
mvn -q exec:java -Dexec.mainClass=com.exemplo.rabbitmq.MSPagamento- MSBilhete
mvn -q exec:java -Dexec.mainClass=com.exemplo.rabbitmq.MSBilhete- MSReserva
mvn -q exec:java -Dexec.mainClass=com.exemplo.rabbitmq.MSReserva- (Optional) AssinantePromocoes (subscribe to
rio/salvador/manaus)
mvn -q exec:java -Dexec.mainClass=com.exemplo.rabbitmq.AssinantePromocoes- (Optional) MSMarketing (publishes promotions with delays)
mvn -q exec:java -Dexec.mainClass=com.exemplo.rabbitmq.MSMarketingThis project intentionally avoids Spring to demonstrate:
- manual exchange/queue declarations
- routing key filtering
- raw RabbitMQ Java client usage
- the core mechanics behind Spring AMQP abstractions
- Use JSON messages (schema/versioning)
- Add manual ack, retries and DLQ
- Add correlation IDs / tracing metadata
- Externalize configuration (host, exchange names, key paths)
- Split into multi-module (one module per microservice)
- Provide a Spring AMQP version for comparison
Educational/demo project — feel free to use as a reference.