Skip to content

Commit

Permalink
Merge pull request #53 from lotteon2/develop
Browse files Browse the repository at this point in the history
[FIX] 재입고 알림 object mapper로 json처리
  • Loading branch information
CessnaJ authored Jan 11, 2024
2 parents 1ef1867 + 32ca086 commit 3819d88
Showing 1 changed file with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.dailyon.productservice.product.sqs.dto.SQSNotificationDto;
import com.dailyon.productservice.product.sqs.dto.enums.NotificationType;
import com.dailyon.productservice.productstock.entity.ProductStock;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.aws.messaging.core.QueueMessagingTemplate;
Expand All @@ -18,15 +19,18 @@
@RequiredArgsConstructor
public class ProductRestockHandler {
private final QueueMessagingTemplate sqsTemplate;
private final ObjectMapper objectMapper;
private final String notificationQueue = "product-restock-notification-queue";

public void produce(List<ProductStock> productStocksToNotify) {
for(ProductStock productStock: productStocksToNotify) {
try {
Message<String> message = MessageBuilder.withPayload(SQSNotificationDto.create(
RawNotificationData.create(productStock, NotificationType.PRODUCT_RESTOCK)
).toString()).build();

String jsonMessage = objectMapper.writeValueAsString(
SQSNotificationDto.create(
RawNotificationData.create(productStock, NotificationType.PRODUCT_RESTOCK)
)
);
Message<String> message = MessageBuilder.withPayload(jsonMessage).build();
sqsTemplate.send(notificationQueue, message);
} catch (Exception e) {
log.error(e.getMessage());
Expand Down

0 comments on commit 3819d88

Please sign in to comment.