-
Notifications
You must be signed in to change notification settings - Fork 0
feat/33 - DLT 컨슈머 #34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
10 changes: 10 additions & 0 deletions
10
src/main/java/com/michelet/inventory/infrastructure/config/JpaConfig.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| package com.michelet.inventory.infrastructure.config; | ||
|
|
||
| import org.springframework.context.annotation.Configuration; | ||
| import org.springframework.data.jpa.repository.config.EnableJpaRepositories; | ||
|
|
||
| @Configuration | ||
| // Redis와 스캔 충돌을 막기 위해 패키지 명시 | ||
| @EnableJpaRepositories(basePackages = "com.michelet.inventory.infrastructure.repository") | ||
| public class JpaConfig { | ||
| } |
57 changes: 57 additions & 0 deletions
57
src/main/java/com/michelet/inventory/infrastructure/messaging/DeadLetterConsumer.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| package com.michelet.inventory.infrastructure.messaging; | ||
|
|
||
| import java.nio.charset.StandardCharsets; | ||
| import lombok.RequiredArgsConstructor; | ||
| import lombok.extern.slf4j.Slf4j; | ||
| import org.apache.kafka.clients.consumer.ConsumerRecord; | ||
| import org.apache.kafka.common.header.Header; | ||
| import org.springframework.kafka.annotation.KafkaListener; | ||
| import org.springframework.kafka.support.KafkaHeaders; | ||
| import org.springframework.stereotype.Component; | ||
|
|
||
| @Slf4j | ||
| @Component | ||
| @RequiredArgsConstructor | ||
| public class DeadLetterConsumer { | ||
|
|
||
| /** | ||
| * Inventory 서비스의 주요 도메인 로직(재고 복구 등) 실패 시 격리된 메시지를 수신 - 3회 재시도 후에도 실패한 '독성 메시지'를 분석하기 위한 전용 컨슈머 | ||
| */ | ||
| @KafkaListener( | ||
| topics = { | ||
| "${inventory.kafka.topic.restore-request:order.stock-restore.requested}.DLT", | ||
| "${inventory.kafka.topic.restored:stock.restored}.DLT", | ||
| "${inventory.kafka.topic.reserved:stock.reserved}.DLT" | ||
| }, | ||
| groupId = "${spring.kafka.consumer.group-id:inventory-service-consumer}-dlt", | ||
| containerFactory = "dltListenerContainerFactory" // String 전용 팩토리 사용 | ||
| ) | ||
| public void consumeInventoryDLT(ConsumerRecord<String, String> record) { | ||
| String originalTopic = extractHeaderAsString(record, KafkaHeaders.DLT_ORIGINAL_TOPIC); | ||
| String exceptionMessage = extractHeaderAsString(record, KafkaHeaders.DLT_EXCEPTION_MESSAGE); | ||
| String stackTrace = extractHeaderAsString(record, KafkaHeaders.DLT_EXCEPTION_STACKTRACE); | ||
|
|
||
| log.error(""" | ||
| ================================================================================ | ||
| [CRITICAL ALERT] 인벤토리 DLT 에러 메시지 격리 수신 (최종 실패) | ||
| 원본 토픽 : {} | ||
| 에러 원인 : {} | ||
| 원본 데이터 : {} | ||
| 상세 트레이스 : | ||
| {} | ||
| ================================================================================""", | ||
| originalTopic, | ||
| exceptionMessage, | ||
| record.value() != null ? record.value() : "데이터 없음", | ||
| stackTrace | ||
| ); | ||
| } | ||
|
|
||
| private String extractHeaderAsString(ConsumerRecord<String, String> record, String headerKey) { | ||
| Header header = record.headers().lastHeader(headerKey); | ||
| if (header != null && header.value() != null) { | ||
| return new String(header.value(), StandardCharsets.UTF_8); | ||
| } | ||
| return "알 수 없음"; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.