MSA 아키텍처 + Kafka 이벤트 기반 통신 실습 프로젝트 Redpanda(카프카 호환 브로커)와 Spring Boot msa를 통한 주문 → 재고 확인 → 알림 전송의 이벤트 흐름
- 비동기 이벤트 기반 통신
- Kafka Producer/Consumer 구조로 이벤트 처리
- Dead Letter Queue (DLQ) 로 장애 주문 처리
- Order-Service
- 사용자 주문 POST /api/orders →
order.created이벤트 발행
- 사용자 주문 POST /api/orders →
- Inventory-Service
order.created소비 → 재고 확인- 성공:
inventory.reserved, 실패:inventory.rejected발행 - 장애 상황: 재시도 후 실패 시 Topic
order.created.DLT
- Notification-Service
inventory.*이벤트 구독 → 알림
msa-kafka-lab/
├─ docker-compose.yml # Redpanda + Kafka UI
├─ order-service/ # 주문 서비스 (producer)
├─ inventory-service/ # 재고 서비스 (consumer+producer, DLQ)
└─ notification-service/ # 알림 서비스 (consumer)
docker compose up -d- Kafka UI: http://localhost:8081
각 서비스 디렉토리(order-service, inventory-service, notification-service)에서 실행:
./gradlew bootRun- KafkaOrder → 8080
- KafkaInventory → 8082
- KafkaNotification → 8083
curl -X POST http://localhost:8080/api/orders -H "Content-Type: application/json" -d '{"userId":42,"items":[{"sku":"ABC-001","qty":2}]}'
응답 예시:
{"orderId":12345,"status":"PENDING"}- 주문 요청과 응답
- order.created topic
- 재고가 없어서 rejected
- fail 요청 reserved 안됨
- dlt topic
- Kafka UI에서 토픽 메시지 확인
inventory-service,notification-service로그 확인
테스트 실패 주문: sku에 Fail 넣음
curl -X POST http://localhost:8080/api/orders -H "Content-Type: application/json" -d '{"userId":42,"items":[{"sku":"FAIL","qty":1}]}'
inventory-service에서 재시도 후 실패 발생- Kafka UI에서
order.created.DLT토픽 생성/메시지 확인
- DB 트랜잭션 연동
- Notification 실제 구현 (이메일/SMS/푸시)