-
Notifications
You must be signed in to change notification settings - Fork 3
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
Conversation
- RedisStreamConsumer 소비자 클래스입니다. - RedisStream에서 메시지를 읽고 pending 상태로 만듭니다. - RedisOperator는 redis의 명령을 추상화하여 다른 클래스에서 쉽게 사용할 수 있도록합니다.
- RedisStreamConsumer에서의 streamkey, consumer group name을 application.yaml에서 관리하도록 변경합니다.
### LazyAuctioneer - 경매 입찰 과정을 비동기로 나중에 처리하는 작업을 실행하기 위한 클래스입니다. ### AuctionPurchaseRequestMessage 데이터 클래스 - 경매 입찰 프로세스에 필요한 최소한의 데이터를 가지고 있는 데이터 클래스입니다.
- RedisStreamConsumer로 부터 Stream에 필요한 정보를 조회하도록 변경하였습니다. - streamKey, consumerGroupName, consumerName이 config에 추가되었습니다.
- 1분 이상 미처리 상태인 메시지를 처리하는 스케줄러를 구현하였습니다.
…/292-redis-stream
public record AuctionPurchaseRequestMessage( | ||
String requestId, | ||
Long buyerId, | ||
Long auctionId, | ||
Long price, | ||
Long quantity, | ||
LocalDateTime requestTime | ||
) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
스트림으로 보낼 구매 요청 메세지를 이곳에 담는군요..! requestId는 UUID! 좋습니다!
@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); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
해당 메서드에서 RedisStream
을 통해 전달된 메세지를 확인하고,
메시지에 맞는 로직을 호출한 뒤 정상처리되면 redisOperator.ack
를 보내는 식으로 동작하는 것인가요?!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
정확합니다!
There was a problem hiding this 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 적용
# 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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔥🔥🔥🔥🔥🔥🔥 LGTM 🔥🔥🔥🔥🔥🔥🔥
📄 Summary
LazyAuctioneer
생성RedisStreamConsumer
생성PendingMessageConsumer
생성📝 Reference
Spring data redis : stream 문서
누군가의 Spring boot 연동 블로그
Redis Stream 관련 공식 문서
close #292