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: Redis Stream 연동을 위한 기반 코드 작성 #294

Merged
merged 16 commits into from
Aug 25, 2024

Conversation

yudonggeun
Copy link
Contributor

@yudonggeun yudonggeun commented Aug 24, 2024

📄 Summary

  • LazyAuctioneer 생성
    • 경매 입찰 완료 처리를 미루고 요청을 우선적으로 대기큐에 적제하는 방식을 적용합니다.
  • RedisStreamConsumer 생성
    • 대기큐에서 요청을 조회하는 역할을 수행하는 클래스입니다.
  • PendingMessageConsumer 생성
    • Pending 상태인 메시지가 일정기간동안 소비되지 않는다면 재처리하는 스케줄러입니다.

image

📝 Reference

Spring data redis : stream 문서
누군가의 Spring boot 연동 블로그
Redis Stream 관련 공식 문서

close #292

- RedisStreamConsumer 소비자 클래스입니다.
    - RedisStream에서 메시지를 읽고 pending 상태로 만듭니다.

- RedisOperator는 redis의 명령을 추상화하여 다른 클래스에서 쉽게 사용할 수 있도록합니다.
- RedisStreamConsumer에서의 streamkey, consumer group name을 application.yaml에서 관리하도록 변경합니다.
### LazyAuctioneer
- 경매 입찰 과정을 비동기로 나중에 처리하는 작업을 실행하기 위한 클래스입니다.

### AuctionPurchaseRequestMessage 데이터 클래스
- 경매 입찰 프로세스에 필요한 최소한의 데이터를 가지고 있는 데이터 클래스입니다.
@yudonggeun yudonggeun added the FEATURE 새로운 기능 또는 변경 label Aug 24, 2024
@yudonggeun yudonggeun requested a review from a team August 24, 2024 04:10
@yudonggeun yudonggeun self-assigned this Aug 24, 2024
yudonggeun and others added 6 commits August 24, 2024 14:05
- RedisStreamConsumer로 부터 Stream에 필요한 정보를 조회하도록 변경하였습니다.
- streamKey, consumerGroupName, consumerName이 config에 추가되었습니다.
- 1분 이상 미처리 상태인 메시지를 처리하는 스케줄러를 구현하였습니다.
Comment on lines +5 to +12
public record AuctionPurchaseRequestMessage(
String requestId,
Long buyerId,
Long auctionId,
Long price,
Long quantity,
LocalDateTime requestTime
) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

스트림으로 보낼 구매 요청 메세지를 이곳에 담는군요..! requestId는 UUID! 좋습니다!

Comment on lines +28 to +34
@Override
public void onMessage(MapRecord<String, Object, Object> message) {
log.info("MessageId: {}", message.getId());
log.info("Stream: {}", message.getStream());
log.info("Body: {}", message.getValue());
redisOperator.acknowledge(redisStreamConfig.getConsumerGroupName(), message);
}
Copy link
Collaborator

@chhs2131 chhs2131 Aug 24, 2024

Choose a reason for hiding this comment

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

해당 메서드에서 RedisStream을 통해 전달된 메세지를 확인하고,
메시지에 맞는 로직을 호출한 뒤 정상처리되면 redisOperator.ack를 보내는 식으로 동작하는 것인가요?!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

정확합니다!

Copy link
Collaborator

@chhs2131 chhs2131 left a comment

Choose a reason for hiding this comment

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

역시 살아숨쉬는 레디스 전자사전~~ 📀

- 테스트 환경에서만 적용되는 값만 치환해서 사용할 수 있도록 application.yaml을 application-test.yaml으로 변경
- ServiceTest, RepositoryTest 프로파일 test 적용
chhs2131
chhs2131 previously approved these changes Aug 25, 2024
# Conflicts:
#	src/main/java/com/wootecam/luckyvickyauction/core/auction/service/auctioneer/BasicAuctioneer.java
#	src/main/java/com/wootecam/luckyvickyauction/core/auction/service/auctioneer/LettuceLockAuctioneerProxy.java
#	src/main/java/com/wootecam/luckyvickyauction/core/auction/service/auctioneer/RedissonLockAuctioneerProxy.java
Copy link
Collaborator

@chhs2131 chhs2131 left a comment

Choose a reason for hiding this comment

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

🔥🔥🔥🔥🔥🔥🔥 LGTM 🔥🔥🔥🔥🔥🔥🔥

@yudonggeun yudonggeun merged commit 5474177 into dev Aug 25, 2024
1 check passed
@yudonggeun yudonggeun deleted the feat/292-redis-stream branch August 25, 2024 06:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
FEATURE 새로운 기능 또는 변경
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[FEATURE] 경매 입찰 요청을 위한 대기 큐 적용
2 participants