Skip to content
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

feat : 주문취소 feign retryer bean 추가 #564

Merged
merged 3 commits into from
Jul 9, 2023

Conversation

gengminy
Copy link
Member

@gengminy gengminy commented Jul 9, 2023

개요

작업사항

  • 주문취소에 멱등성을 위한 5xx 에러 retry 옵션 추가 (최대 3번 retry)

변경로직

  • 내용을 적어주세요.

@gengminy gengminy added the For: API [이슈 대상] 외부 API label Jul 9, 2023
@gengminy gengminy self-assigned this Jul 9, 2023
@@ -12,7 +12,7 @@

@FeignClient(
name = "PaymentsCancelClient",
url = "https://api.tosspayments.com",
url = "${feign.toss.url}",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

가리는거 좋아용

Comment on lines 20 to 28
private static final long PERIOD = 100L;
private static final long MAX_PERIOD = TimeUnit.SECONDS.toMillis(3L);
private static final int MAX_ATTEMPTS = 3;

@Bean
Retryer.Default retryer() {
return new Retryer.Default(PERIOD, MAX_PERIOD, MAX_ATTEMPTS);
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

오호 이런방식으로 하는거군요 배워갑니당

Comment on lines 20 to 43
// private final static String IDEMPOTENCY_KEY = "idempotency-key";
// private final static String PAYMENT_KEY = "1234";
// private final static CancelPaymentsRequest REQUEST =
// CancelPaymentsRequest.builder().cancelReason("test").build();
// @Autowired
// private PaymentsCancelClient paymentsCancelClient;
//
// @Test
// public void 주문취소_실패시_멱등성_테스트() {
// final String URL = "/v1/payments/" + PAYMENT_KEY + "/cancel";
// // given
// stubFor(post(urlEqualTo(URL))
// .willReturn(aResponse()
// .withStatus(HttpStatus.SERVICE_UNAVAILABLE)));
//
// // when
// Throwable exception = catchThrowable(
// () -> paymentsCancelClient.execute(IDEMPOTENCY_KEY, PAYMENT_KEY, REQUEST));
//
// // then
// assertThat(exception).isInstanceOf(RetryableException.class);
// verify(3, postRequestedFor(urlEqualTo(URL)));
// }
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

고민의 흔적....

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

비상탈출...

Copy link
Member

@sanbonai06 sanbonai06 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

수고하셨습니당

@sonarcloud
Copy link

sonarcloud bot commented Jul 9, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 1 Code Smell

71.4% 71.4% Coverage
0.0% 0.0% Duplication

Comment on lines 28 to +31
@Override
public Exception decode(String methodKey, Response response) {
TossPaymentsErrorDto body = TossPaymentsErrorDto.from(response);
try {
PaymentsCancelErrorCode paymentsCancelErrorCode =
FeignException exception = feign.FeignException.errorStatus(methodKey, response);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gengminy

에러 디코더는 도는게 맞는데
TossPaymentsErrorDto 를 먼저해버려서
응답값 파싱중에
unhandleException 먼저 되버린 문제였습니다!

바디파싱은 뒤로미루고
500 번대 먼저 캐치해서 리트라이 했어요

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

response 를 먼저 읽어서 그렇군요 확인입니다

@ImNM ImNM merged commit 5478555 into dev Jul 9, 2023
3 checks passed
@ImNM ImNM deleted the feature/557-order-cancel-feign-retry branch July 9, 2023 12:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
For: API [이슈 대상] 외부 API
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

🔨[refactor] 결제 취소 feign retry 옵션
3 participants