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

[#64] 결제 실패 흐름 구현 #66

Merged
merged 8 commits into from
Aug 31, 2024
Merged

[#64] 결제 실패 흐름 구현 #66

merged 8 commits into from
Aug 31, 2024

Conversation

hyeok-kong
Copy link
Collaborator

개발 내용

  • 결제 실패 시 실패 저항 플로우 구현

개발 코멘트

  • 결제가 된 이후 발생할 문제에 대해 중복 결제를 막기 위한 플로우를 구현했습니다.
  • 이벤트 처리 시점을 통해 결제 후 동작이 진행됐는지 파악하며, batch job을 통해 재시도 로직을 구현할 예정입니다.

@hyeok-kong hyeok-kong added the enhancement New feature or request label Aug 31, 2024
@hyeok-kong hyeok-kong self-assigned this Aug 31, 2024
@@ -62,6 +64,8 @@ public ConsumerFactory<String, GroupMemberIncreaseRequestDto> groupIncreaseConsu
public ConcurrentKafkaListenerContainerFactory<String, GroupMemberIncreaseRequestDto> groupIncreaseKafkaListenerContainerFactory() {
ConcurrentKafkaListenerContainerFactory<String, GroupMemberIncreaseRequestDto> factory = new ConcurrentKafkaListenerContainerFactory<>();
factory.setConsumerFactory(groupIncreaseConsumerFactory());
factory.getContainerProperties().setAckMode(ContainerProperties.AckMode.MANUAL);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

스프링 카프카의 자동 커밋을 해제했습니다. 이유는 다음과 같습니다.

  1. 결제 완료 후 문제가 생길 경우 동일한 결제 이벤트 처리 가능성 (중복 결제)
  2. 이벤트 컨슘 후 즉시 커밋함으로써 한 번 진행한 결제 이벤트의 재처리 방지

payService.processPayRequest(dto);
public void listen(GroupMemberIncreaseRequestDto message, Acknowledgment ack) {
// 메시지를 받자마자 이벤트 히스토리 기록 & 커밋하기
PayEvent payEvent = payEventService.savePayEvent(message);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

결제 이벤트를 수신한 후 히스토리를 남기고 바로 커밋합니다.

이후 실패에 대해선 DB 에 적재된 히스토리를 통해 재시도합니다.

kafkaProducer.send(GROUP_MEMBER_INCREASE_RESPONSE, groupMemberIncreaseMapper.toResponse(dto, status));
}
// 이벤트 완전 처리 시점 기록
payEvent.getBaseEvent().setProcessedAt(LocalDateTime.now());
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

결제 성공 후, 결제 성공 이벤트 발행 전 문제가 발생한다면 이벤트 처리 시점이 기록되지 않습니다.

@@ -64,7 +64,7 @@ public ConsumerFactory<String, GroupMemberIncreaseRequestDto> groupIncreaseConsu
public ConcurrentKafkaListenerContainerFactory<String, GroupMemberIncreaseRequestDto> groupIncreaseKafkaListenerContainerFactory() {
ConcurrentKafkaListenerContainerFactory<String, GroupMemberIncreaseRequestDto> factory = new ConcurrentKafkaListenerContainerFactory<>();
factory.setConsumerFactory(groupIncreaseConsumerFactory());
factory.getContainerProperties().setAckMode(ContainerProperties.AckMode.MANUAL);
factory.getContainerProperties().setAckMode(ContainerProperties.AckMode.MANUAL_IMMEDIATE);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

MANUAL 옵션의 경우 다음 poll() 시점에 커밋을 진행합니다. 이는 기존 의도와 맞지 않으므로, 즉시 커밋하는 MANUAL_IMMEDIATE 옵션으로 변경하였습니다.

@hyeok-kong hyeok-kong merged commit 550cbfd into main Aug 31, 2024
1 check passed
@hyeok-kong hyeok-kong linked an issue Aug 31, 2024 that may be closed by this pull request
@hyeok-kong hyeok-kong deleted the feature/64 branch September 30, 2024 05:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

이벤트 실패 시 처리 로직 구현
1 participant