From 3f5939d7a565310b90d7f346dc7936a0142b81b1 Mon Sep 17 00:00:00 2001 From: Chanwoong Park <128444378+chanchanwoong@users.noreply.github.com> Date: Tue, 25 Jun 2024 20:14:42 +0900 Subject: [PATCH 1/3] =?UTF-8?q?feat:=20=ED=8C=8C=ED=8B=B0=EC=85=98=20?= =?UTF-8?q?=EB=B0=8F=20=EB=A0=88=ED=94=8C=EB=A6=AC=EC=B9=B4=202=EA=B0=9C?= =?UTF-8?q?=EB=A1=9C=20=EC=88=98=EC=A0=95(#220)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../auction/kafka/KafkaProducerConfig.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/skyhorsemanpower/auction/kafka/KafkaProducerConfig.java b/src/main/java/com/skyhorsemanpower/auction/kafka/KafkaProducerConfig.java index 6429d55..8ac2368 100644 --- a/src/main/java/com/skyhorsemanpower/auction/kafka/KafkaProducerConfig.java +++ b/src/main/java/com/skyhorsemanpower/auction/kafka/KafkaProducerConfig.java @@ -38,8 +38,8 @@ public KafkaTemplate kafkaTemplate() { @Bean public NewTopic auctionCloseTopic() { return TopicBuilder.name(Topics.Constant.AUCTION_CLOSE) - .partitions(1) - .replicas(1) + .partitions(2) + .replicas(2) .config(TopicConfig.RETENTION_MS_CONFIG, String.valueOf(172800000)) .build(); } @@ -47,8 +47,8 @@ public NewTopic auctionCloseTopic() { @Bean public NewTopic alarmTopic() { return TopicBuilder.name(Topics.Constant.ALARM) - .partitions(1) - .replicas(1) + .partitions(2) + .replicas(2) .config(TopicConfig.RETENTION_MS_CONFIG, String.valueOf(172800000)) .build(); } From 26620a4b1edcc79733be73b469374904c1af3d6c Mon Sep 17 00:00:00 2001 From: Chanwoong Park <128444378+chanchanwoong@users.noreply.github.com> Date: Wed, 26 Jun 2024 11:41:07 +0900 Subject: [PATCH 2/3] =?UTF-8?q?feat:=20=EA=B2=BD=EB=A7=A4=EA=B8=80=20?= =?UTF-8?q?=EC=A2=85=EB=A3=8C=20=EC=8B=9C=EA=B0=84=EC=97=90=20=EB=8F=84?= =?UTF-8?q?=EB=8B=AC=ED=95=9C=20=EB=9D=BC=EC=9A=B4=EB=93=9C=20=EC=B2=98?= =?UTF-8?q?=EB=A6=AC(#214)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../skyhorsemanpower/auction/domain/RoundInfo.java | 12 +++++++++++- .../auction/kafka/KafkaConsumerCluster.java | 6 +++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/skyhorsemanpower/auction/domain/RoundInfo.java b/src/main/java/com/skyhorsemanpower/auction/domain/RoundInfo.java index 03ae0ad..ed18c58 100644 --- a/src/main/java/com/skyhorsemanpower/auction/domain/RoundInfo.java +++ b/src/main/java/com/skyhorsemanpower/auction/domain/RoundInfo.java @@ -30,11 +30,14 @@ public class RoundInfo { private Long numberOfParticipants; private Long leftNumberOfParticipants; private LocalDateTime createdAt; + private LocalDateTime auctionEndTime; + private Boolean isLastRound; @Builder public RoundInfo(String auctionUuid, Integer round, LocalDateTime roundStartTime, LocalDateTime roundEndTime, BigDecimal incrementUnit, BigDecimal price, Boolean isActive, Long numberOfParticipants, - Long leftNumberOfParticipants, LocalDateTime createdAt) { + Long leftNumberOfParticipants, LocalDateTime createdAt, + LocalDateTime auctionEndTime, Boolean isLastRound) { this.auctionUuid = auctionUuid; this.round = round; this.roundStartTime = roundStartTime; @@ -45,6 +48,8 @@ public RoundInfo(String auctionUuid, Integer round, LocalDateTime roundStartTime this.numberOfParticipants = numberOfParticipants; this.leftNumberOfParticipants = leftNumberOfParticipants; this.createdAt = LocalDateTime.now(); + this.auctionEndTime = auctionEndTime; + this.isLastRound = isLastRound; } public static RoundInfo nextRoundUpdate(RoundInfo roundInfo) { @@ -52,6 +57,10 @@ public static RoundInfo nextRoundUpdate(RoundInfo roundInfo) { LocalDateTime nextRoundStartTime = LocalDateTime.now().plusSeconds(StandbyTimeEnum.SECONDS_15.getSecond()); LocalDateTime nextRoundEndTime = nextRoundStartTime.plusSeconds(RoundTimeEnum.SECONDS_60.getSecond()); BigDecimal nextPrice = roundInfo.getPrice().add(roundInfo.getIncrementUnit()); + LocalDateTime auctionEndTime = roundInfo.getAuctionEndTime(); + + // nextRoundStartTime <= auctionEndTime <= nextRoundEndTime 인 경우 다음 라운드가 마지막 라운드 + boolean isLastRound = nextRoundStartTime.isBefore(auctionEndTime) && auctionEndTime.isBefore(nextRoundEndTime); return RoundInfo.builder() .auctionUuid(roundInfo.getAuctionUuid()) @@ -63,6 +72,7 @@ public static RoundInfo nextRoundUpdate(RoundInfo roundInfo) { .isActive(false) // 대기 상태로 변경 .numberOfParticipants(roundInfo.getNumberOfParticipants()) .leftNumberOfParticipants(roundInfo.getNumberOfParticipants()) + .isLastRound(isLastRound) .build(); } diff --git a/src/main/java/com/skyhorsemanpower/auction/kafka/KafkaConsumerCluster.java b/src/main/java/com/skyhorsemanpower/auction/kafka/KafkaConsumerCluster.java index 2f5ce13..3087261 100644 --- a/src/main/java/com/skyhorsemanpower/auction/kafka/KafkaConsumerCluster.java +++ b/src/main/java/com/skyhorsemanpower/auction/kafka/KafkaConsumerCluster.java @@ -5,6 +5,7 @@ import com.skyhorsemanpower.auction.domain.RoundInfo; import com.skyhorsemanpower.auction.kafka.data.dto.InitialAuctionDto; import com.skyhorsemanpower.auction.repository.RoundInfoRepository; +import com.skyhorsemanpower.auction.status.AuctionTimeEnum; import com.skyhorsemanpower.auction.status.RoundTimeEnum; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -25,7 +26,7 @@ public class KafkaConsumerCluster { private final RoundInfoRepository roundInfoRepository; private final QuartzJobConfig quartzJobConfig; - @KafkaListener(topics = Topics.Constant.INITIAL_AUCTION, groupId = "${spring.kafka.consumer.group-id}") + @KafkaListener(topics = "1", groupId = "${spring.kafka.consumer.group-id}") public void initialAuction(@Payload LinkedHashMap message, @Headers MessageHeaders messageHeaders) { log.info("consumer: success >>> message: {}, headers: {}", message.toString(), @@ -56,6 +57,7 @@ private void initialRoundInfo(InitialAuctionDto initialAuctionDto) { // Instant 타입을 LocalDateTime 변환 LocalDateTime roundStartTime = DateTimeConverter. instantToLocalDateTime(initialAuctionDto.getAuctionStartTime()); + LocalDateTime auctionEndTime = roundStartTime.plusHours(AuctionTimeEnum.MINUTES_120.getMinute()); RoundInfo roundinfo = RoundInfo.builder() .auctionUuid(initialAuctionDto.getAuctionUuid()) @@ -68,6 +70,8 @@ private void initialRoundInfo(InitialAuctionDto initialAuctionDto) { .numberOfParticipants((long) initialAuctionDto.getNumberOfEventParticipants()) .leftNumberOfParticipants((long) initialAuctionDto.getNumberOfEventParticipants()) .createdAt(LocalDateTime.now()) + .auctionEndTime(auctionEndTime) + .isLastRound(false) .build(); log.info("Initial round_info >>> {}", roundinfo); From 2066c57ac0777a944fa13dac4ceea34617c67f83 Mon Sep 17 00:00:00 2001 From: Chanwoong Park <128444378+chanchanwoong@users.noreply.github.com> Date: Wed, 26 Jun 2024 12:18:13 +0900 Subject: [PATCH 3/3] =?UTF-8?q?feat:=20=EA=B2=BD=EB=A7=A4=EA=B8=80=20?= =?UTF-8?q?=EC=A2=85=EB=A3=8C=20=EC=8B=9C=EA=B0=84=20=EB=8F=84=EB=8B=AC=20?= =?UTF-8?q?=EC=8B=9C=20isLastRound=20=3D=20true=20=EB=B3=80=ED=99=98=20?= =?UTF-8?q?=ED=99=95=EC=9D=B8(#214)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/skyhorsemanpower/auction/domain/RoundInfo.java | 5 +++++ .../skyhorsemanpower/auction/kafka/KafkaConsumerCluster.java | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/skyhorsemanpower/auction/domain/RoundInfo.java b/src/main/java/com/skyhorsemanpower/auction/domain/RoundInfo.java index ed18c58..e1e3ff3 100644 --- a/src/main/java/com/skyhorsemanpower/auction/domain/RoundInfo.java +++ b/src/main/java/com/skyhorsemanpower/auction/domain/RoundInfo.java @@ -72,6 +72,7 @@ public static RoundInfo nextRoundUpdate(RoundInfo roundInfo) { .isActive(false) // 대기 상태로 변경 .numberOfParticipants(roundInfo.getNumberOfParticipants()) .leftNumberOfParticipants(roundInfo.getNumberOfParticipants()) + .auctionEndTime(roundInfo.getAuctionEndTime()) .isLastRound(isLastRound) .build(); } @@ -89,6 +90,8 @@ public static RoundInfo currentRoundUpdate(RoundInfo roundInfo) { .isActive(true) .numberOfParticipants(roundInfo.getNumberOfParticipants()) .leftNumberOfParticipants(nextNumberOfParticipants) + .auctionEndTime(roundInfo.getAuctionEndTime()) + .isLastRound(roundInfo.getIsLastRound()) .build(); } @@ -103,6 +106,8 @@ public static RoundInfo setIsActiveTrue(RoundInfo roundInfo) { .isActive(true) .numberOfParticipants(roundInfo.getNumberOfParticipants()) .leftNumberOfParticipants(roundInfo.getLeftNumberOfParticipants()) + .auctionEndTime(roundInfo.getAuctionEndTime()) + .isLastRound(roundInfo.getIsLastRound()) .createdAt(LocalDateTime.now()) .build(); } diff --git a/src/main/java/com/skyhorsemanpower/auction/kafka/KafkaConsumerCluster.java b/src/main/java/com/skyhorsemanpower/auction/kafka/KafkaConsumerCluster.java index 3087261..5db03f3 100644 --- a/src/main/java/com/skyhorsemanpower/auction/kafka/KafkaConsumerCluster.java +++ b/src/main/java/com/skyhorsemanpower/auction/kafka/KafkaConsumerCluster.java @@ -26,7 +26,7 @@ public class KafkaConsumerCluster { private final RoundInfoRepository roundInfoRepository; private final QuartzJobConfig quartzJobConfig; - @KafkaListener(topics = "1", groupId = "${spring.kafka.consumer.group-id}") + @KafkaListener(topics = Topics.Constant.INITIAL_AUCTION, groupId = "${spring.kafka.consumer.group-id}") public void initialAuction(@Payload LinkedHashMap message, @Headers MessageHeaders messageHeaders) { log.info("consumer: success >>> message: {}, headers: {}", message.toString(), @@ -57,7 +57,7 @@ private void initialRoundInfo(InitialAuctionDto initialAuctionDto) { // Instant 타입을 LocalDateTime 변환 LocalDateTime roundStartTime = DateTimeConverter. instantToLocalDateTime(initialAuctionDto.getAuctionStartTime()); - LocalDateTime auctionEndTime = roundStartTime.plusHours(AuctionTimeEnum.MINUTES_120.getMinute()); + LocalDateTime auctionEndTime = roundStartTime.plusMinutes(AuctionTimeEnum.MINUTES_120.getMinute()); RoundInfo roundinfo = RoundInfo.builder() .auctionUuid(initialAuctionDto.getAuctionUuid())