Skip to content

Commit f199032

Browse files
committed
feat: 상품 조회 메시지 정의
1 parent dfbb0cd commit f199032

3 files changed

Lines changed: 36 additions & 3 deletions

File tree

apps/commerce-api/src/main/java/com/loopers/application/product/ProductFacade.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import com.loopers.domain.brand.BrandRepository;
55
import com.loopers.domain.product.Product;
66
import com.loopers.domain.product.ProductRepository;
7+
import com.loopers.domain.product.ProductViewedMessage;
8+
import com.loopers.infrastructure.product.ProductViewKafkaProducer;
79
import com.loopers.interfaces.api.product.ProductV1Dto;
810
import com.loopers.support.error.CoreException;
911
import com.loopers.support.error.ErrorType;
@@ -16,14 +18,14 @@
1618

1719
import java.math.BigDecimal;
1820
import java.util.List;
21+
import java.util.UUID;
1922

2023
@Component
2124
@RequiredArgsConstructor
2225
public class ProductFacade {
2326
private final ProductRepository productRepository;
2427
private final BrandRepository brandRepository;
25-
private final ApplicationEventPublisher publisher;
26-
28+
private final ProductViewKafkaProducer kafkaProducer;
2729

2830
@Transactional
2931
public ProductInfo registerProduct(ProductV1Dto.ProductRequest request) {
@@ -57,7 +59,13 @@ public ProductInfo findProductById(Long id) {
5759
);
5860

5961
// 유저 ID는 임시로 하드 코딩했습니다. 추후 인증/인가 기능이 추가되면 수정할 예정입니다.
60-
publisher.publishEvent(new UserActionEvent(1L, product.getId(), ActionType.PRODUCT_LOOKED_UP));
62+
ProductViewedMessage message = new ProductViewedMessage(
63+
UUID.randomUUID().toString(),
64+
1L,
65+
product.getId()
66+
);
67+
68+
kafkaProducer.sendProductViewedMessage(message);
6169

6270
return ProductInfo.from(product);
6371
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package com.loopers.domain.product;
2+
3+
public record ProductViewedMessage(
4+
String eventId,
5+
Long userId,
6+
Long productId
7+
) {
8+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.loopers.infrastructure.product;
2+
3+
import com.loopers.domain.product.ProductViewedMessage;
4+
import lombok.RequiredArgsConstructor;
5+
import org.springframework.kafka.core.KafkaTemplate;
6+
import org.springframework.stereotype.Component;
7+
8+
9+
@Component
10+
@RequiredArgsConstructor
11+
public class ProductViewKafkaProducer {
12+
private final KafkaTemplate<Object, Object> kafkaTemplate;
13+
14+
public void sendProductViewedMessage(ProductViewedMessage message) {
15+
kafkaTemplate.send("product-viewed-topic", message);
16+
}
17+
}

0 commit comments

Comments
 (0)