-
Notifications
You must be signed in to change notification settings - Fork 3
feat : 장애 대응 및 재처리 로직을 적용한 고가용성 알림 시스템 구축 #195
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 10 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
5157ef4
fix : mysql 드라이버 불러오지 못하는 문제 해결
NCookies e9b554e
feat : MongoDB 트랜잭션 도입 및 적용 테스트
NCookies 3f30088
refactor : 트랜잭션 관련 코드 개선
NCookies 134c69b
feat : 알림 데이터 저장 시 DB 장애 시를 대비하여 서킷 브레이커 패턴 적용
NCookies b1321c0
feat : 서킷 브레이커 정상적으로 동작하도록 수정
NCookies dead37d
feat : consumer에서 메시지 처리 중 에러가 발생했을 때를 대비해 상태 기반 재처리 로직 구현
NCookies e0faa16
feat : 테스트 코드가 항상 성공하도록 수정
NCookies cfa613b
feat : 스크립트 shebang 추가
NCookies f2badc9
feat : Mongo 트랜잭션 매니저 Bean 이름 충돌 문제 해결
NCookies 1712ec9
feat : 커스텀 메시지 ID 누락 시 무한 재시도 위험 문제 해결
NCookies ad90a91
refact : 메시지 처리 메서드 호출 시 messageId에 해당하는 데이터가 없을 경우 로그 추가
NCookies 90cc69a
Merge branch 'dev' into feature/notification-failure-recover
NCookies 6f780f3
refact : 더 이상 사용되지 않는 테스트 코드 disabled
NCookies 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
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 |
|---|---|---|
|
|
@@ -43,6 +43,7 @@ src/main/resources/application.properties | |
| docker-compose.dev.yml | ||
| /data/ | ||
| /db/ | ||
| /replicaset | ||
|
|
||
| # 환경변수 | ||
| .env | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| #!/bin/bash | ||
|
|
||
| DATA_FILE_PATH="./replicaset" | ||
| DOCKER_FILE_PATH="./docker-compose.dev.yml" | ||
| MONGO_PRIMARY_NAME="rs01p" | ||
| REPLICA_INIT_FILE_PATH="./scripts/rs-init.sh" | ||
| MONGO_CREATE_USER_FILE_PATH="./scripts/mongo-create-user.sh" | ||
NCookies marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| UP_CONTAINER_DELAY=10 | ||
| REPLICA_CONFIG_DELAY=25 | ||
|
|
||
| echo "****************** Reset docker container Shell Script ******************" | ||
| echo "Data File Path: ${DATA_FILE_PATH}" | ||
| echo "Docker File Path: ${DOCKER_FILE_PATH}" | ||
| echo "MongoDB Primary name: ${MONGO_PRIMARY_NAME}" | ||
| echo "Replica set init Script File Path: ${REPLICA_INIT_FILE_PATH}" | ||
| echo "Mongo create user file path: ${MONGO_CREATE_USER_FILE_PATH}" | ||
|
|
||
| sleep 1; | ||
|
|
||
| echo "****************** Stop docker container ******************" | ||
| docker-compose -f ${DOCKER_FILE_PATH} stop | ||
| echo "****************** Completed Stop docker container ******************" | ||
|
|
||
| sleep 1; | ||
|
|
||
| echo "****************** Down docker container ******************" | ||
| docker-compose -f ${DOCKER_FILE_PATH} down | ||
| echo "****************** Completed Down docker container ******************" | ||
|
|
||
| sleep 1; | ||
|
|
||
| echo "****************** Remove Data ******************" | ||
| rm -rf ${DATA_FILE_PATH} | ||
| echo "****************** Completed Remove Data ******************" | ||
|
|
||
| sleep 1; | ||
|
|
||
| echo "****************** Up docker container ******************" | ||
| docker-compose -f ${DOCKER_FILE_PATH} up -d | ||
| echo "****************** Completed Up docker container ******************" | ||
|
|
||
| echo "****** Waiting for ${UP_CONTAINER_DELAY} seconds ******" | ||
| sleep $UP_CONTAINER_DELAY; | ||
|
|
||
| echo "****************** Run Replica Set Shell Script ******************" | ||
| docker exec -i ${MONGO_PRIMARY_NAME} bash < ${REPLICA_INIT_FILE_PATH} | ||
|
|
||
| echo "****** Waiting for ${REPLICA_CONFIG_DELAY} seconds for replicaset configuration to be applied ******" | ||
| sleep $REPLICA_CONFIG_DELAY | ||
|
|
||
| echo "****************** Run Create DB User Shell Script ******************" | ||
| docker exec -i ${MONGO_PRIMARY_NAME} bash < "${MONGO_CREATE_USER_FILE_PATH}" | ||
|
|
||
| echo "****************** Completed Replica Shell Script ******************" | ||
NCookies marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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,16 @@ | ||
| #!/bin/bash | ||
|
|
||
| mongosh --port 10021 <<EOF | ||
NCookies marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| use admin; | ||
| db.createUser({ | ||
| user: "mongo", | ||
| pwd: "mongo123", | ||
| roles: [ | ||
| { | ||
| role: "dbOwner", | ||
| db: "ezcode", | ||
| }, | ||
| ], | ||
| }); | ||
| db.getUsers(); | ||
| EOF | ||
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,30 @@ | ||
| #!/bin/bash | ||
|
|
||
| mongosh --port 10021 <<EOF | ||
NCookies marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| use ezcode; | ||
| var config = { | ||
| "_id": "rs01", | ||
| "version": 1, | ||
| "members": [ | ||
| { | ||
| "_id": 1, | ||
| "host": "rs01p:10021", | ||
| "priority": 2 | ||
| }, | ||
| { | ||
| "_id": 2, | ||
| "host": "rs01s:10022", | ||
| "priority": 1 | ||
| }, | ||
| { | ||
| "_id": 3, | ||
| "host": "rs01a:10023", | ||
| "priority": 0 | ||
| } | ||
| ] | ||
| }; | ||
| rs.initiate(config); | ||
| rs.status(); | ||
| db.setProfilingLevel(2); | ||
| db.getProfilingStatus(); | ||
| EOF | ||
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
15 changes: 15 additions & 0 deletions
15
src/main/java/org/ezcode/codetest/infrastructure/mongo/config/MongoTransactionConfig.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,15 @@ | ||
| package org.ezcode.codetest.infrastructure.mongo.config; | ||
|
|
||
| import org.springframework.context.annotation.Bean; | ||
| import org.springframework.context.annotation.Configuration; | ||
| import org.springframework.data.mongodb.MongoDatabaseFactory; | ||
| import org.springframework.data.mongodb.MongoTransactionManager; | ||
|
|
||
| @Configuration | ||
| public class MongoTransactionConfig { | ||
|
|
||
| @Bean(name = "mongoTransactionManager") | ||
| public MongoTransactionManager transactionManager(MongoDatabaseFactory mongoDatabaseFactory) { | ||
| return new MongoTransactionManager(mongoDatabaseFactory); | ||
| } | ||
| } |
12 changes: 12 additions & 0 deletions
12
...in/java/org/ezcode/codetest/infrastructure/notification/event/NotificationSavedEvent.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,12 @@ | ||
| package org.ezcode.codetest.infrastructure.notification.event; | ||
|
|
||
| import org.ezcode.codetest.infrastructure.notification.dto.NotificationResponse; | ||
|
|
||
| public record NotificationSavedEvent( | ||
|
|
||
| String principalName, | ||
|
|
||
| NotificationResponse response | ||
|
|
||
| ) { | ||
| } |
72 changes: 72 additions & 0 deletions
72
...in/java/org/ezcode/codetest/infrastructure/notification/model/NotificationProcessLog.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,72 @@ | ||
| package org.ezcode.codetest.infrastructure.notification.model; | ||
|
|
||
| import java.time.LocalDateTime; | ||
|
|
||
| import org.springframework.data.mongodb.core.mapping.Document; | ||
|
|
||
| import org.springframework.data.annotation.Id; | ||
| import lombok.AccessLevel; | ||
| import lombok.AllArgsConstructor; | ||
| import lombok.Getter; | ||
| import lombok.NoArgsConstructor; | ||
|
|
||
| @Document(collection = "notification_process_log") | ||
| @Getter | ||
| @NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
| @AllArgsConstructor | ||
| public class NotificationProcessLog { | ||
|
|
||
| @Id | ||
| private String messageId; | ||
|
|
||
| private String payload; | ||
|
|
||
| private ProcessStatus status; | ||
|
|
||
| private int retryCount; | ||
|
|
||
| private String errorMessage; | ||
|
|
||
| private LocalDateTime lastAttemptAt; | ||
|
|
||
| private LocalDateTime createdAt; | ||
|
|
||
| public enum ProcessStatus { | ||
| PENDING, SUCCESS, FAILED, PERMANENTLY_FAILED | ||
| } | ||
|
|
||
| public static NotificationProcessLog of(String messageId, String payload) { | ||
|
|
||
| return new NotificationProcessLog( | ||
| messageId, | ||
| payload, | ||
| ProcessStatus.PENDING, | ||
| 0, | ||
| null, | ||
| LocalDateTime.now(), | ||
| LocalDateTime.now() | ||
| ); | ||
| } | ||
|
|
||
| public void markAsSuccess() { | ||
| this.status = ProcessStatus.SUCCESS; | ||
| this.lastAttemptAt = LocalDateTime.now(); | ||
| this.errorMessage = null; | ||
| } | ||
|
|
||
| public void markAsFailed(String errorMessage, int maxRetries) { | ||
| this.retryCount++; | ||
| this.lastAttemptAt = LocalDateTime.now(); | ||
| this.errorMessage = errorMessage; | ||
|
|
||
| if (this.retryCount >= maxRetries) { | ||
| this.status = ProcessStatus.PERMANENTLY_FAILED; | ||
| } else { | ||
| this.status = ProcessStatus.FAILED; | ||
| } | ||
| } | ||
|
|
||
| public void updateLastAttempt() { | ||
| this.lastAttemptAt = LocalDateTime.now(); | ||
| } | ||
| } |
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
12 changes: 12 additions & 0 deletions
12
...ode/codetest/infrastructure/notification/repository/NotificationProcessLogRepository.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,12 @@ | ||
| package org.ezcode.codetest.infrastructure.notification.repository; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| import org.ezcode.codetest.infrastructure.notification.model.NotificationProcessLog; | ||
| import org.springframework.data.mongodb.repository.MongoRepository; | ||
|
|
||
| public interface NotificationProcessLogRepository extends MongoRepository<NotificationProcessLog, String> { | ||
|
|
||
| // 재시도할 작업들을 찾는 쿼리 메서드 | ||
| List<NotificationProcessLog> findByStatusAndRetryCountLessThan(NotificationProcessLog.ProcessStatus status, int maxRetries); | ||
| } |
Oops, something went wrong.
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.