-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Message Listener와 Scheduler가 서로 메세지를 읽으면 입금이 중복으로 발생할 수 있는 문제를 발견했습니다. - 마지막으로 읽은 시간이 일정 시간이 넘어야 하고 ack를 완료했을 때만 입금 로직을 처리할 수 있도록 변경했습니다.
- Loading branch information
1 parent
7a46b29
commit 7240ae2
Showing
17 changed files
with
421 additions
and
42 deletions.
There are no files selected for viewing
This file contains 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 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
16 changes: 16 additions & 0 deletions
16
...ain/java/org/c4marathon/assignment/bankaccount/exception/async/AccountAsyncErrorCode.java
This file contains 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 @@ | ||
package org.c4marathon.assignment.bankaccount.exception.async; | ||
|
||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@Getter | ||
@RequiredArgsConstructor | ||
public enum AccountAsyncErrorCode { | ||
SEND_ROLLBACK_FAILED("이체 롤백에 실패했습니다"), | ||
; | ||
private final String message; | ||
|
||
public AccountAsyncException accountAsyncException() { | ||
return new AccountAsyncException(name(), getMessage()); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
...ain/java/org/c4marathon/assignment/bankaccount/exception/async/AccountAsyncException.java
This file contains 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 @@ | ||
package org.c4marathon.assignment.bankaccount.exception.async; | ||
|
||
import lombok.Getter; | ||
|
||
@Getter | ||
public class AccountAsyncException extends RuntimeException { | ||
private final String errorName; | ||
private final String message; | ||
private final Exception exception; | ||
|
||
public AccountAsyncException(String errorName, String message) { | ||
this.errorName = errorName; | ||
this.message = message; | ||
this.exception = null; | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
...a/org/c4marathon/assignment/bankaccount/exception/async/AccountAsyncExceptionHandler.java
This file contains 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 @@ | ||
package org.c4marathon.assignment.bankaccount.exception.async; | ||
|
||
import java.lang.reflect.Method; | ||
import java.lang.reflect.Parameter; | ||
|
||
import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
|
||
@Slf4j | ||
public class AccountAsyncExceptionHandler implements AsyncUncaughtExceptionHandler { | ||
|
||
@Override | ||
public void handleUncaughtException(Throwable ex, Method method, Object... params) { | ||
StringBuilder sb = new StringBuilder(); | ||
|
||
Parameter[] parameters = method.getParameters(); | ||
int parameterIndex = 0; | ||
for (Object param : params) { | ||
sb.append(parameters[parameterIndex++]).append(" = ").append(param).append(" , "); | ||
} | ||
AccountAsyncException exception = (AccountAsyncException)ex; | ||
|
||
// 실제 환경에서는 메일 같은 것으로 에러 발생을 알려줘야 할 것 같다. | ||
log.error( | ||
"error name : {} | error message: {} | error method: {} | error parameters: ", | ||
exception.getErrorName(), exception.getMessage(), method.getName(), | ||
sb); | ||
} | ||
} |
This file contains 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 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 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 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 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
27 changes: 27 additions & 0 deletions
27
src/main/java/org/c4marathon/assignment/bankaccount/service/SendRollbackHandlerService.java
This file contains 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,27 @@ | ||
package org.c4marathon.assignment.bankaccount.service; | ||
|
||
import org.c4marathon.assignment.bankaccount.exception.async.AccountAsyncErrorCode; | ||
import org.c4marathon.assignment.bankaccount.repository.MainAccountRepository; | ||
import org.springframework.scheduling.annotation.Async; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class SendRollbackHandlerService { | ||
private final MainAccountRepository mainAccountRepository; | ||
|
||
@Async("rollbackExecutor") | ||
@Transactional | ||
public void rollBackDeposit(long sendPk, long depositPk, long money) { | ||
int updateResult = mainAccountRepository.deposit(sendPk, money); | ||
|
||
// 상대 계좌에 업데이트가 되지 않은 경우 롤백 실패 예외가 발생한다. | ||
if (updateResult == 0) { | ||
throw AccountAsyncErrorCode.SEND_ROLLBACK_FAILED.accountAsyncException(); | ||
} | ||
|
||
} | ||
} |
Oops, something went wrong.