You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Sistema distribuído de processamento de pagamentos com Spring Boot e RabbitMQ, implementando Dead Letter Queue (DLQ), retry manual com backoff e ACK manual.
📋 Índice
Arquitetura
Tecnologias
Estrutura do Projeto
Configuração RabbitMQ
Fluxo de Mensagens
Instalação e Execução
API Endpoints
Regras de Negócio
Mecanismo de Retry
Dead Letter Queue
Monitoramento
Testes
Troubleshooting
Arquitetura
flowchart LR
A[Service A<br/>API REST :8081] -->|RabbitMQ Exchange| B[(RabbitMQ<br/>Topic Exchange)]
B --> C[Service B<br/>Processor :8082]
C -->|ACK OK| D[(Mensagem Consumida)]
C -->|Falha após retries| E[(DLX<br/>Direct Exchange)]
E --> F[Queue DLQ]
F --> G[Service C<br/>DLQ Monitor :8083]
sequenceDiagram
participant A as Service A
participant MQ as RabbitMQ
participant B as Service B
A->>MQ: Publica pagamento.processar
MQ->>B: Entrega mensagem
B->>B: Processa pagamento
B->>MQ: basicAck()
MQ-->>B: Mensagem removida
Loading
2. Retry (Falha temporária)
sequenceDiagram
participant B as Service B
participant MQ as Queue
B->>MQ: Consome mensagem (tentativa 1)
B->>MQ: Reject + requeue
MQ->>B: Reentrega
B->>MQ: Tentativa 2
B->>MQ: Reject + requeue
B->>MQ: Tentativa 3
B->>MQ: ACK ou DLQ
Loading
3. Fluxo para DLQ
flowchart TD
A[Service B consome mensagem]
B{Falhou 3x?}
C[Rejeita sem requeue]
D[DLX recebe mensagem]
E[DLQ: pagamento.fila.dlq]
F[Service C processa erro]
G[Log em payment_errors.log]
A --> B
B -- Não --> A
B -- Sim --> C --> D --> E --> F --> G
Loading
Instalação e Execução
1. Subir RabbitMQ
docker-compose up -d
2. Build
mvn clean install -DskipTests
3. Rodar serviços
# Service A
mvn spring-boot:run
# Service B
mvn spring-boot:run
# Service C
mvn spring-boot:run
API Endpoints
POST /api/orders/process-payment
Campo
Tipo
Obrigatório
customerId
String
Sim
amount
Decimal
Sim
paymentMethod
String
Não
curl -X POST "http://localhost:8081/api/orders/process-payment?customerId=123&amount=100"
Regras de Negócio
Regra
Resultado
amount > 10000
Rejeita
customerId termina 99
Rejeita
padrão
70% sucesso
Mecanismo de Retry
flowchart LR
A[Recebe mensagem]
B{Sucesso?}
C[ACK]
D{Retry < 3?}
E[Reject + republish]
F[DLQ]
A --> B
B -- Sim --> C
B -- Não --> D
D -- Sim --> E
D -- Não --> F
Loading
Dead Letter Queue (DLQ)
flowchart LR
A[pagamento.fila]
B[pedidos.dlx]
C[pagamento.fila.dlq]
D[Service C Monitor]
A --> B --> C --> D
foriin {1..20};do
curl -X POST "http://localhost:8081/api/orders/process-payment?customerId=$i&amount=100"&done
Troubleshooting
DLQ não recebendo mensagens
rabbitmqctl list_bindings | grep dlx
Filas travadas
rabbitmqctl purge_queue pagamento.fila
Performance
Métrica
Valor
Throughput
50–100 msg/s
Latência
< 200ms
Prefetch
1
Licença
MIT
About
Sistema distribuído de processamento de pagamentos com Spring Boot e RabbitMQ, utilizando retry manual, ACK manual e Dead Letter Queue (DLQ) para resiliência e tratamento de falhas.