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

🐛 Fix new order event notification #21

Merged
merged 4 commits into from
Dec 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -60,7 +59,7 @@ public void publishNewComerNotification(NotificationData<Void> notification) {
notificationCommandService.saveSingleNotification(notification.getPublishInformation(), 1L);
}

public void publishNewOrderNotification(NotificationData<NewOrderNotification> notification) {
public void publishNewOrderNotification(NotificationData<NewOrderEventItem> notification) {
NotificationInformation sseNotification =
NotificationInformation.getSSEData(
notification.getPublishInformation(), notification.getWhoToNotify().getStoreId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,29 @@
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;
import org.springframework.messaging.handler.annotation.Headers;
import org.springframework.messaging.handler.annotation.Payload;
import org.springframework.stereotype.Service;

@Slf4j
@Service
@RequiredArgsConstructor
public class NotificationSQSListener {
Expand Down Expand Up @@ -107,25 +110,32 @@ public void consumeQuestionRegisterNotificationQueue(
public void consumeNewOrderNotificationQueue(
@Payload String message, @Headers Map<String, String> headers, Acknowledgment ack)
throws JsonProcessingException {
// TODO: 주문 완료 후 타입 정의해서 보내주기 kind
NotificationData<NewOrderNotification> newOrderNotification =
objectMapper.readValue(
message,
objectMapper
.getTypeFactory()
.constructParametricType(NotificationData.class, NewOrderNotification.class));
NotificationData<NewOrderNotification> 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<NewOrderEventItem> 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();
}

/**
* 신규 회원 가입 심사 알림
*
Expand Down
2 changes: 2 additions & 0 deletions src/test/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ cloud:
name: ""
sns:
arn: ""
new-order-event:
arn: ""
credentials:
ACCESS_KEY_ID: "test"
SECRET_ACCESS_KEY: "test"
Expand Down
Loading