From 64aec0fda538a84fe0e71db596df536b8ec61e2d Mon Sep 17 00:00:00 2001 From: sunmingLee <25thbam@gmail.com> Date: Wed, 29 Oct 2025 09:56:32 +0900 Subject: [PATCH] =?UTF-8?q?distribution-completed=20Kafka=20=EC=9D=B4?= =?UTF-8?q?=EB=B2=A4=ED=8A=B8=20=ED=98=95=EC=8B=9D=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - DistributedChannelInfo DTO 추가 (channel, channelType, status, expectedViews) - ChannelType enum에 category 필드 추가 (TV, CALL, SNS 구분) - DistributionCompletedEvent 구조 변경 (distributedChannels를 상세 정보 리스트로 변경) - completedAt 필드에 @JsonFormat 추가하여 ISO 8601 문자열 형식으로 직렬화 - publishDistributionCompletedEvent 메서드 수정하여 새로운 형식으로 이벤트 발행 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- .../com/kt/distribution/dto/ChannelType.java | 20 ++++++---- .../event/DistributedChannelInfo.java | 40 +++++++++++++++++++ .../event/DistributionCompletedEvent.java | 16 ++------ .../service/DistributionService.java | 17 ++++---- .../service/KafkaEventPublisher.java | 4 +- 5 files changed, 67 insertions(+), 30 deletions(-) create mode 100644 distribution-service/src/main/java/com/kt/distribution/event/DistributedChannelInfo.java diff --git a/distribution-service/src/main/java/com/kt/distribution/dto/ChannelType.java b/distribution-service/src/main/java/com/kt/distribution/dto/ChannelType.java index 8a92b3b..0d9d727 100644 --- a/distribution-service/src/main/java/com/kt/distribution/dto/ChannelType.java +++ b/distribution-service/src/main/java/com/kt/distribution/dto/ChannelType.java @@ -7,20 +7,26 @@ package com.kt.distribution.dto; * @since 2025-10-23 */ public enum ChannelType { - URIDONGNETV("우리동네TV"), - RINGOBIZ("링고비즈"), - GINITV("지니TV"), - INSTAGRAM("Instagram"), - NAVER("Naver Blog"), - KAKAO("Kakao Channel"); + URIDONGNETV("우리동네TV", "TV"), + RINGOBIZ("링고비즈", "CALL"), + GINITV("지니TV", "TV"), + INSTAGRAM("Instagram", "SNS"), + NAVER("Naver Blog", "SNS"), + KAKAO("Kakao Channel", "SNS"); private final String displayName; + private final String category; - ChannelType(String displayName) { + ChannelType(String displayName, String category) { this.displayName = displayName; + this.category = category; } public String getDisplayName() { return displayName; } + + public String getCategory() { + return category; + } } diff --git a/distribution-service/src/main/java/com/kt/distribution/event/DistributedChannelInfo.java b/distribution-service/src/main/java/com/kt/distribution/event/DistributedChannelInfo.java new file mode 100644 index 0000000..83e2f8a --- /dev/null +++ b/distribution-service/src/main/java/com/kt/distribution/event/DistributedChannelInfo.java @@ -0,0 +1,40 @@ +package com.kt.distribution.event; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * 배포된 채널 정보 + * Kafka 이벤트에 포함되는 채널별 상세 정보 + * + * @author System Architect + * @since 2025-10-29 + */ +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class DistributedChannelInfo { + + /** + * 채널명 (예: "우리동네TV", "지니TV", "링고비즈") + */ + private String channel; + + /** + * 채널 타입 (예: "TV", "CALL", "SNS") + */ + private String channelType; + + /** + * 배포 상태 (SUCCESS, FAILED) + */ + private String status; + + /** + * 예상 조회수 + */ + private Integer expectedViews; +} diff --git a/distribution-service/src/main/java/com/kt/distribution/event/DistributionCompletedEvent.java b/distribution-service/src/main/java/com/kt/distribution/event/DistributionCompletedEvent.java index 467b6a6..d1563a9 100644 --- a/distribution-service/src/main/java/com/kt/distribution/event/DistributionCompletedEvent.java +++ b/distribution-service/src/main/java/com/kt/distribution/event/DistributionCompletedEvent.java @@ -1,5 +1,6 @@ package com.kt.distribution.event; +import com.fasterxml.jackson.annotation.JsonFormat; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; @@ -27,22 +28,13 @@ public class DistributionCompletedEvent { private String eventId; /** - * 배포 완료된 채널 목록 + * 배포 완료된 채널 상세 정보 목록 */ - private List distributedChannels; + private List distributedChannels; /** * 배포 완료 시각 */ + @JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss.SSSSSSS") private LocalDateTime completedAt; - - /** - * 성공한 채널 수 - */ - private int successCount; - - /** - * 실패한 채널 수 - */ - private int failureCount; } diff --git a/distribution-service/src/main/java/com/kt/distribution/service/DistributionService.java b/distribution-service/src/main/java/com/kt/distribution/service/DistributionService.java index 3b314f8..9b05107 100644 --- a/distribution-service/src/main/java/com/kt/distribution/service/DistributionService.java +++ b/distribution-service/src/main/java/com/kt/distribution/service/DistributionService.java @@ -116,7 +116,7 @@ public class DistributionService { saveCompletedStatus(request.getEventId(), results, startedAt, completedAt, successCount, failureCount); // Kafka Event 발행 -// publishDistributionCompletedEvent(request.getEventId(), results); + publishDistributionCompletedEvent(request.getEventId(), results); // 응답 생성 return DistributionResponse.builder() @@ -244,20 +244,19 @@ public class DistributionService { return; } - List distributedChannels = results.stream() - .filter(ChannelDistributionResult::isSuccess) - .map(result -> result.getChannel().name()) + List distributedChannels = results.stream() + .map(result -> com.kt.distribution.event.DistributedChannelInfo.builder() + .channel(result.getChannel().getDisplayName()) + .channelType(result.getChannel().getCategory()) + .status(result.isSuccess() ? "SUCCESS" : "FAILED") + .expectedViews(result.getEstimatedReach()) + .build()) .collect(Collectors.toList()); - long successCount = results.stream().filter(ChannelDistributionResult::isSuccess).count(); - long failureCount = results.size() - successCount; - DistributionCompletedEvent event = DistributionCompletedEvent.builder() .eventId(eventId) .distributedChannels(distributedChannels) .completedAt(LocalDateTime.now()) - .successCount((int) successCount) - .failureCount((int) failureCount) .build(); kafkaEventPublisher.get().publishDistributionCompleted(event); diff --git a/distribution-service/src/main/java/com/kt/distribution/service/KafkaEventPublisher.java b/distribution-service/src/main/java/com/kt/distribution/service/KafkaEventPublisher.java index 65ac7cb..fe1782d 100644 --- a/distribution-service/src/main/java/com/kt/distribution/service/KafkaEventPublisher.java +++ b/distribution-service/src/main/java/com/kt/distribution/service/KafkaEventPublisher.java @@ -36,8 +36,8 @@ public class KafkaEventPublisher { */ public void publishDistributionCompleted(DistributionCompletedEvent event) { try { - log.info("Publishing DistributionCompletedEvent: eventId={}, successCount={}, failureCount={}", - event.getEventId(), event.getSuccessCount(), event.getFailureCount()); + log.info("Publishing DistributionCompletedEvent: eventId={}, channels={}", + event.getEventId(), event.getDistributedChannels().size()); CompletableFuture> future = kafkaTemplate.send(distributionCompletedTopic, event.getEventId(), event);