역경매 서비스의 실시간 알림 서버입니다. Redis Pub/Sub로 경매 이벤트를 수신하여 PostgreSQL에 저장하고, SSE(Server-Sent Events)로 사용자에게 실시간 알림을 전달합니다.
auction (메인 서버)
│ Redis Pub/Sub 발행 (auction:notification)
▼
NotificationMessageListener
│ JSON 역직렬화 → NotificationService.save()
▼
PostgreSQL (Notification 저장)
│ 트랜잭션 커밋 후 SSE 전송
▼
SseEmitterService ──► 연결된 클라이언트 (SSE)
| NotificationType | 메시지 |
|---|---|
AUCTION_STARTED |
'[itemName]' 경매가 시작됐습니다. |
NEW_BID |
'[itemName]' 경매에 새 입찰이 들어왔습니다. |
LOWEST_BID_UPDATED |
'[itemName]' 경매에 더 낮은 입찰이 들어왔습니다. 재입찰을 고려해보세요. |
AUCTION_CLOSED_WIN |
축하합니다! '[itemName]' 경매에 낙찰됐습니다. |
AUCTION_CLOSED_BUYER |
'[itemName]' 경매의 낙찰자가 결정됐습니다. |
AUCTION_NO_BID |
'[itemName]' 경매가 입찰자 없이 종료됐습니다. |
GET /api/notifications/subscribe— SSE 구독 (클라이언트당 하나의 emitter 유지)- 30초 간격 ping으로 커넥션 유지
- 트랜잭션 커밋 후 SSE 전송 (
TransactionSynchronization)으로 데이터 정합성 보장 - 가상 스레드 기반 비동기 처리 (Java 21)
| Method | Endpoint | 설명 |
|---|---|---|
GET |
/api/notifications |
알림 목록 조회 (생성일 내림차순) |
PATCH |
/api/notifications/{id}/read |
단건 읽음 처리 |
PATCH |
/api/notifications/read-all |
전체 읽음 처리 |
DELETE |
/api/notifications/{id} |
단건 삭제 |
DELETE |
/api/notifications |
전체 삭제 |
com.example.auctionnotification/
├── common/
│ ├── config/
│ │ ├── redis/ # RedisConfig, RedisSubscriberConfig
│ │ └── security/ # SecurityConfig, JwtProvider, JwtAuthenticationFilter
│ ├── dto/ # BaseResponse
│ └── exception/ # GlobalExceptionHandler, ServiceErrorException
│
└── notification/
├── controller/ # NotificationController, NotificationTestController
├── service/ # NotificationService, SseEmitterService
├── listener/ # NotificationMessageListener (Redis Pub/Sub)
├── repository/ # NotificationRepository
├── entity/ # Notification
├── dto/ # NotificationMessage, NotificationResponse
└── enums/ # NotificationType
| 변수명 | 설명 | 필수 |
|---|---|---|
POSTGRES_URL |
PostgreSQL JDBC URL | ✅ |
POSTGRES_USERNAME |
DB 사용자명 | ✅ |
POSTGRES_PASSWORD |
DB 비밀번호 | ✅ |
REDIS_HOST |
Redis 호스트 | ✅ |
JWT_SECRET |
JWT 서명 키 (32자 이상) | ✅ |
REDIS_SSL_ENABLED |
Redis SSL 활성화 여부 (기본값: false) |
❌ |
- Java 21
- Docker / Docker Compose
프로젝트 루트에 .env 파일을 생성합니다.
POSTGRES_URL=jdbc:postgresql://localhost:5432/auction_notification
POSTGRES_USERNAME=postgres
POSTGRES_PASSWORD=your_password
REDIS_HOST=localhost
JWT_SECRET=your_jwt_secret_key_min_32_charsdocker compose up -d postgres redis./gradlew bootRun --args='--spring.profiles.active=dev'서버가 뜨면 http://localhost:8081 로 접근할 수 있습니다.