From 5a143d0570d48ea42ca93aa1472dd62d9075eea2 Mon Sep 17 00:00:00 2001 From: Raja Kolli Date: Sun, 28 Sep 2025 11:06:56 +0000 Subject: [PATCH 1/2] Refactor KafkaListenerConfig to remove unused ObjectMapper and simplify product event handling --- .../inventoryservice/config/KafkaListenerConfig.java | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/inventory-service/src/main/java/com/example/inventoryservice/config/KafkaListenerConfig.java b/inventory-service/src/main/java/com/example/inventoryservice/config/KafkaListenerConfig.java index 884b0f98a..b726befdb 100644 --- a/inventory-service/src/main/java/com/example/inventoryservice/config/KafkaListenerConfig.java +++ b/inventory-service/src/main/java/com/example/inventoryservice/config/KafkaListenerConfig.java @@ -12,7 +12,6 @@ Licensed under MIT License Copyright (c) 2022-2025 Raja Kolli. import com.example.inventoryservice.services.ProductManageService; import com.example.inventoryservice.utils.AppConstants; import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.ObjectMapper; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.context.annotation.Configuration; @@ -34,15 +33,12 @@ class KafkaListenerConfig { private final InventoryOrderManageService orderManageService; private final ProductManageService productManageService; - private final ObjectMapper objectMapper; KafkaListenerConfig( InventoryOrderManageService orderManageService, - ProductManageService productManageService, - ObjectMapper objectMapper) { + ProductManageService productManageService) { this.orderManageService = orderManageService; this.productManageService = productManageService; - this.objectMapper = objectMapper; } // retries if processing of event fails @@ -60,9 +56,10 @@ public void onEvent(OrderDto orderDto) { } @KafkaListener(id = "products", topics = AppConstants.PRODUCT_TOPIC, groupId = "product") - public void onSaveProductEvent(@Payload String productDto) throws JsonProcessingException { + public void onSaveProductEvent(@Payload @Valid ProductDto productDto) + throws JsonProcessingException { log.info("Received Product: {}", productDto); - productManageService.manage(objectMapper.readValue(productDto, ProductDto.class)); + productManageService.manage(productDto); } @DltHandler From 45b08c6db167781b70906d21f59eb263eb5b9d5a Mon Sep 17 00:00:00 2001 From: Raja Kolli Date: Sun, 28 Sep 2025 11:23:32 +0000 Subject: [PATCH 2/2] fix : import issue --- .../com/example/inventoryservice/config/KafkaListenerConfig.java | 1 + 1 file changed, 1 insertion(+) diff --git a/inventory-service/src/main/java/com/example/inventoryservice/config/KafkaListenerConfig.java b/inventory-service/src/main/java/com/example/inventoryservice/config/KafkaListenerConfig.java index b726befdb..36be4e6fa 100644 --- a/inventory-service/src/main/java/com/example/inventoryservice/config/KafkaListenerConfig.java +++ b/inventory-service/src/main/java/com/example/inventoryservice/config/KafkaListenerConfig.java @@ -12,6 +12,7 @@ Licensed under MIT License Copyright (c) 2022-2025 Raja Kolli. import com.example.inventoryservice.services.ProductManageService; import com.example.inventoryservice.utils.AppConstants; import com.fasterxml.jackson.core.JsonProcessingException; +import jakarta.validation.Valid; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.context.annotation.Configuration;