diff --git a/build.gradle b/build.gradle index 8ea3aec..4b61c92 100644 --- a/build.gradle +++ b/build.gradle @@ -44,7 +44,7 @@ dependencies { implementation 'org.springframework.cloud:spring-cloud-aws-messaging:2.2.4.RELEASE' implementation 'org.springframework.kafka:spring-kafka' implementation 'software.amazon.awssdk:sns:2.21.37' - implementation 'io.github.lotteon-maven:blooming-blooms-utils:202312220850' + implementation 'io.github.lotteon-maven:blooming-blooms-utils:202312260649' testImplementation 'org.mockito:mockito-core:4.8.0' diff --git a/src/main/java/kr/bb/notification/domain/notification/helper/NotificationActionHelper.java b/src/main/java/kr/bb/notification/domain/notification/helper/NotificationActionHelper.java index 7ac9748..697a392 100644 --- a/src/main/java/kr/bb/notification/domain/notification/helper/NotificationActionHelper.java +++ b/src/main/java/kr/bb/notification/domain/notification/helper/NotificationActionHelper.java @@ -2,17 +2,16 @@ import bloomingblooms.domain.notification.NotificationData; import bloomingblooms.domain.notification.delivery.DeliveryNotification; -import bloomingblooms.domain.notification.order.NewOrderNotification; import bloomingblooms.domain.notification.order.OrderCancelNotification; import bloomingblooms.domain.notification.order.SettlementNotification; import bloomingblooms.domain.notification.question.InqueryResponseNotification; import bloomingblooms.domain.notification.question.QuestionRegister; import bloomingblooms.domain.notification.stock.OutOfStockNotification; +import bloomingblooms.domain.order.NewOrderEvent.NewOrderEventItem; import bloomingblooms.domain.resale.ResaleNotificationList; import java.util.List; import kr.bb.notification.domain.notification.application.NotificationCommandService; import kr.bb.notification.domain.notification.entity.NotificationCommand.NotificationInformation; - import kr.bb.notification.domain.notification.infrastructure.sms.SendSMS; import kr.bb.notification.domain.notification.infrastructure.sse.SendSSE; import lombok.RequiredArgsConstructor; @@ -60,7 +59,7 @@ public void publishNewComerNotification(NotificationData notification) { notificationCommandService.saveSingleNotification(notification.getPublishInformation(), 1L); } - public void publishNewOrderNotification(NotificationData notification) { + public void publishNewOrderNotification(NotificationData notification) { NotificationInformation sseNotification = NotificationInformation.getSSEData( notification.getPublishInformation(), notification.getWhoToNotify().getStoreId()); diff --git a/src/main/java/kr/bb/notification/domain/notification/infrastructure/message/NotificationSQSListener.java b/src/main/java/kr/bb/notification/domain/notification/infrastructure/message/NotificationSQSListener.java index 9c72b3e..0531856 100644 --- a/src/main/java/kr/bb/notification/domain/notification/infrastructure/message/NotificationSQSListener.java +++ b/src/main/java/kr/bb/notification/domain/notification/infrastructure/message/NotificationSQSListener.java @@ -5,19 +5,21 @@ import bloomingblooms.domain.notification.Role; import bloomingblooms.domain.notification.delivery.DeliveryNotification; import bloomingblooms.domain.notification.newcomer.NewcomerNotification; -import bloomingblooms.domain.notification.order.NewOrderNotification; import bloomingblooms.domain.notification.order.OrderCancelNotification; import bloomingblooms.domain.notification.order.SettlementNotification; import bloomingblooms.domain.notification.question.InqueryResponseNotification; import bloomingblooms.domain.notification.question.QuestionRegister; import bloomingblooms.domain.notification.stock.OutOfStockNotification; +import bloomingblooms.domain.order.NewOrderEvent; +import bloomingblooms.domain.order.NewOrderEvent.NewOrderEventItem; import bloomingblooms.domain.resale.ResaleNotificationList; import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import java.util.Map; import kr.bb.notification.domain.notification.helper.NotificationActionHelper; - import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; import org.springframework.cloud.aws.messaging.listener.Acknowledgment; import org.springframework.cloud.aws.messaging.listener.SqsMessageDeletionPolicy; import org.springframework.cloud.aws.messaging.listener.annotation.SqsListener; @@ -25,6 +27,7 @@ import org.springframework.messaging.handler.annotation.Payload; import org.springframework.stereotype.Service; +@Slf4j @Service @RequiredArgsConstructor public class NotificationSQSListener { @@ -107,25 +110,32 @@ public void consumeQuestionRegisterNotificationQueue( public void consumeNewOrderNotificationQueue( @Payload String message, @Headers Map headers, Acknowledgment ack) throws JsonProcessingException { - // TODO: 주문 완료 후 타입 정의해서 보내주기 kind - NotificationData newOrderNotification = - objectMapper.readValue( - message, - objectMapper - .getTypeFactory() - .constructParametricType(NotificationData.class, NewOrderNotification.class)); - NotificationData notification = - NotificationData.notifyData( - newOrderNotification.getWhoToNotify(), - PublishNotificationInformation.updateRole( - newOrderNotification.getPublishInformation(), Role.MANAGER)); + // sns 에서 발생한 이벤트 sqs 에서 받기 + String messageFromSNS = getMessageFromSNS(message); + NewOrderEvent newOrderEvent = objectMapper.readValue(messageFromSNS, NewOrderEvent.class); - // call facade - notificationActionHelper.publishNewOrderNotification(notification); + newOrderEvent + .getOrders() + .forEach( + item -> { + NotificationData notificationData = + NotificationData.notifyData( + item, + PublishNotificationInformation.makePublishNotificationInformation( + NewOrderEventItem.getNotificationURL(item.getOrderType()), + NewOrderEventItem.getNotificationKind(item.getOrderType()), + Role.MANAGER)); + notificationActionHelper.publishNewOrderNotification(notificationData); + }); ack.acknowledge(); } + private String getMessageFromSNS(String message) throws JsonProcessingException { + JsonNode jsonNode = objectMapper.readTree(message); + return jsonNode.get("Message").asText(); + } + /** * 신규 회원 가입 심사 알림 * diff --git a/src/test/resources/application.yml b/src/test/resources/application.yml index 1f558dc..46077a0 100644 --- a/src/test/resources/application.yml +++ b/src/test/resources/application.yml @@ -33,6 +33,8 @@ cloud: name: "" sns: arn: "" + new-order-event: + arn: "" credentials: ACCESS_KEY_ID: "test" SECRET_ACCESS_KEY: "test"