feat(order, notification, kafka): 주문 상태 변경 시 kafka 메시지 발송

This commit is contained in:
bum12ark
2022-03-23 16:05:26 +09:00
parent 5e50b5c98e
commit 1c2751c7bc
9 changed files with 58 additions and 10 deletions

View File

@@ -34,6 +34,17 @@ public class NotificationConsumer {
notificationService.insertOrderPlaced(kafkaSendOrderDto.getUserId(), kafkaSendOrderDto.getStoreId());
}
@Transactional
@KafkaListener(topics = "orderAccepted")
public void orderAccepted(String kafkaMessage) throws JsonProcessingException {
log.debug("## NotificationConsumer.orderAccepted");
log.debug("#### kafka Message = {}", kafkaMessage);
KafkaSendOrderDto orderDto = objectMapper.readValue(kafkaMessage, KafkaSendOrderDto.class);
notificationService.insertOrderAccepted(orderDto.userId, orderDto.storeId);
}
@Data @NoArgsConstructor
static class KafkaSendOrderDto {
private Long id;

View File

@@ -11,4 +11,5 @@ public interface NotificationService {
void updateNotification(UpdateNotificationDto dto);
Long findNotificationCounts(Long userId, Yn readYn);
void insertOrderPlaced(Long userId, Long storeId);
void insertOrderAccepted(Long userId, Long storeId);
}

View File

@@ -59,9 +59,22 @@ public class NotificationServiceImpl implements NotificationService {
GetStoreResponse storeResponse = storeClient.getStore(String.valueOf(storeId)).getData();
String title = "주문이 신청되었어요.";
String storeName = "[" + storeResponse.getName() + "]";
String storeName = "[" + storeResponse.getName() + "] ";
String message = storeName + "매장의 주문이 신청되었습니다.";
Notification notification = Notification.of(userId, message, title);
notificationRepository.save(notification);
}
@Transactional
@Override
public void insertOrderAccepted(Long userId, Long storeId) {
GetStoreResponse storeInfo = storeClient.getStore(String.valueOf(storeId)).getData();
String title = "주문이 수락되었어요.";
String storeName = "[" + storeInfo.getName() + "] ";
String message = storeName + "매장의 주문이 수락되었습니다.";
Notification notification = Notification.of(userId, message, title);
notificationRepository.save(notification);
}
}