diff --git a/inventory/inventory-service/src/main/java/org/ecommerce/api/CategoryAPI.java b/inventory/inventory-service/src/main/java/org/ecommerce/api/CategoryAPI.java index 0f57940b..99a47d83 100644 --- a/inventory/inventory-service/src/main/java/org/ecommerce/api/CategoryAPI.java +++ b/inventory/inventory-service/src/main/java/org/ecommerce/api/CategoryAPI.java @@ -41,7 +41,7 @@ public Response getCategoryById(@PathParam("id") UUID id) { .build(); } - @DELETE + /*@DELETE @Path("/delete/{id}") @Consumes(MediaType.APPLICATION_JSON) public Response removeCategoryById(@PathParam("id") UUID id) { @@ -64,6 +64,6 @@ public Response updateCategoryById(@PathParam("id") UUID id, Category updatedCat return Response.ok(categoryRepository.updateCategory(updatedCategory)).build(); } return Response.status(Response.Status.NOT_FOUND).build(); - } + }*/ } diff --git a/inventory/inventory-service/src/main/java/org/ecommerce/events/MinimalEvent.java b/inventory/inventory-service/src/main/java/org/ecommerce/events/MinimalEvent.java index 86e87bf8..5320803b 100644 --- a/inventory/inventory-service/src/main/java/org/ecommerce/events/MinimalEvent.java +++ b/inventory/inventory-service/src/main/java/org/ecommerce/events/MinimalEvent.java @@ -4,7 +4,7 @@ //The MinimalEvent will be sent for the events that require knowing only the id product public class MinimalEvent { - private UUID eventID; + //private UUID eventID; private UUID productId; private String eventType; @@ -15,13 +15,13 @@ public MinimalEvent(UUID productId,String eventType){ this.eventType=eventType; } - public UUID getEventID() { - return eventID; - } - - public void setEventID(UUID eventID) { - this.eventID = eventID; - } +// public UUID getEventID() { +// return eventID; +// } +// +// public void setEventID(UUID eventID) { +// this.eventID = eventID; +// } public UUID getProductId() { return productId; diff --git a/inventory/inventory-service/src/main/java/org/ecommerce/events/PricingEvent.java b/inventory/inventory-service/src/main/java/org/ecommerce/events/PricingEvent.java new file mode 100644 index 00000000..867d5c33 --- /dev/null +++ b/inventory/inventory-service/src/main/java/org/ecommerce/events/PricingEvent.java @@ -0,0 +1,20 @@ +package org.ecommerce.events; + +import java.util.UUID; + +public class PricingEvent { + private UUID productId; + + public PricingEvent(){} + + public PricingEvent(UUID id){ + this.productId=id; + } + public UUID getProductId() { + return productId; + } + + public void setProductId(UUID productId) { + this.productId = productId; + } +} diff --git a/inventory/inventory-service/src/main/java/org/ecommerce/events/ProductEvent.java b/inventory/inventory-service/src/main/java/org/ecommerce/events/ProductEvent.java index 84e5b604..dbc15a7d 100644 --- a/inventory/inventory-service/src/main/java/org/ecommerce/events/ProductEvent.java +++ b/inventory/inventory-service/src/main/java/org/ecommerce/events/ProductEvent.java @@ -4,7 +4,7 @@ //The ProductEvent will be sent for the events that require knowing the hole product -public class ProductEvent extends MinimalEvent { +public class ProductEvent extends MinimalEvent { private int totalQuantity; private int reservedQuantity; @@ -21,6 +21,14 @@ public ProductEvent(UUID productId, int totalQuantity, int reservedQuantity,Stri } + public Category getCategory() { + return category; + } + + public void setCategory(Category category) { + this.category = category; + } + public int getTotalQuantity() { return totalQuantity; } diff --git a/inventory/inventory-service/src/main/java/org/ecommerce/service/EventConsumerService.java b/inventory/inventory-service/src/main/java/org/ecommerce/service/EventConsumerService.java index 67b3e4c4..451cd28f 100644 --- a/inventory/inventory-service/src/main/java/org/ecommerce/service/EventConsumerService.java +++ b/inventory/inventory-service/src/main/java/org/ecommerce/service/EventConsumerService.java @@ -40,7 +40,7 @@ public void consumeOrderCreationEvent(String orderEventJSON)throws JsonProcessin } - @Incoming("order-status")//waiting for the true order topic + @Incoming("order-status-update")//waiting for the true order topic @Transactional public void consumeOrderStatusEvent(String orderEventJSON)throws JsonProcessingException { try{ diff --git a/inventory/inventory-service/src/main/java/org/ecommerce/service/EventProducerService.java b/inventory/inventory-service/src/main/java/org/ecommerce/service/EventProducerService.java index 6a2e858f..b780866b 100644 --- a/inventory/inventory-service/src/main/java/org/ecommerce/service/EventProducerService.java +++ b/inventory/inventory-service/src/main/java/org/ecommerce/service/EventProducerService.java @@ -8,6 +8,7 @@ import jakarta.inject.Inject; import jakarta.persistence.PostPersist; import org.ecommerce.events.MinimalEvent; +import org.ecommerce.events.PricingEvent; import org.ecommerce.events.ProductEvent; import org.ecommerce.model.Product; @@ -26,6 +27,12 @@ public class EventProducerService { @Channel("product-availability") Emitter disponibiltyEventEmitter; + + //This event will send only the id to the topic (for the pricing microservice) + @Inject + @Channel("product-created-id") + Emitter pricingEventEmitter; + @PostPersist public void sendProductEvent(Product product, String eventType) throws JsonProcessingException { ProductEvent productEvent = new ProductEvent( @@ -69,4 +76,16 @@ public void produceMinimalEvent(MinimalEvent productEvent) throws JsonProcessing } } + + @PostPersist + public void producePricingEvent(PricingEvent pricingEvent) throws JsonProcessingException { + try{ + //String jsonEvent = new Gson().toJson(productEvent); + String productJSON=objectMapper.writeValueAsString(pricingEvent); + pricingEventEmitter.send(productJSON);} + catch (Exception e){ + e.printStackTrace(); + } + } + } diff --git a/inventory/inventory-service/src/main/java/org/ecommerce/service/ProductService.java b/inventory/inventory-service/src/main/java/org/ecommerce/service/ProductService.java index 91eed83c..e793b557 100644 --- a/inventory/inventory-service/src/main/java/org/ecommerce/service/ProductService.java +++ b/inventory/inventory-service/src/main/java/org/ecommerce/service/ProductService.java @@ -3,6 +3,7 @@ import java.util.Optional; import java.util.UUID; import com.fasterxml.jackson.core.JsonProcessingException; +import org.ecommerce.events.PricingEvent; import org.ecommerce.model.AvailabilityCheckDTO; import org.ecommerce.model.Item; import org.ecommerce.model.OrderDTO; @@ -30,6 +31,9 @@ public Product addNewProduct(Product product) throws JsonProcessingException { repo.addProduct(product); //Send an event "CREATE" to the topic "product-events" eventProducerService.sendProductEvent(product, "CREATE"); + //send an event (containing only the id of the product to the pricing microservice ) + PricingEvent pricingEvent=new PricingEvent(product.getId()); + eventProducerService.producePricingEvent(pricingEvent); return product; } diff --git a/inventory/inventory-service/src/main/resources/application.properties b/inventory/inventory-service/src/main/resources/application.properties index aa32815d..ca2ed2ce 100644 --- a/inventory/inventory-service/src/main/resources/application.properties +++ b/inventory/inventory-service/src/main/resources/application.properties @@ -15,14 +15,23 @@ kafka.bootstrap.servers=localhost:9092 mp.messaging.outgoing.product-events.connector=smallrye-kafka mp.messaging.outgoing.product-events.topic=product-events mp.messaging.outgoing.product-events.value.serializer=org.apache.kafka.common.serialization.StringSerializer -# config for topic product-disponibility to the catalog service -mp.messaging.outgoing.product-disponibility.connector=smallrye-kafka -mp.messaging.outgoing.product-disponibility.topic=product-availability -mp.messaging.outgoing.product-disponibility.value.serializer=org.apache.kafka.common.serialization.StringSerializer +# config for topic product-availability to the catalog service +mp.messaging.outgoing.product-availability.connector=smallrye-kafka +mp.messaging.outgoing.product-availability.topic=product-availability +mp.messaging.outgoing.product-availability.value.serializer=org.apache.kafka.common.serialization.StringSerializer + +#config the pricing event for the pricing microservice +mp.messaging.outgoing.product-created-id.connector=smallrye-kafka +mp.messaging.outgoing.product-created-id.topic=product-created-id +mp.messaging.outgoing.product-created-id.value.serializer=org.apache.kafka.common.serialization.StringSerializer + + #Config reception de messages kafka mp.messaging.incoming.order-creation.connector=smallrye-kafka -mp.messaging.incoming.order-creation.topic=product-events +mp.messaging.incoming.order-creation.topic=order-creation mp.messaging.incoming.order-creation.value.deserializer=org.apache.kafka.common.serialization.StringDeserializer -mp.messaging.incoming.order-status.connector=smallrye-kafka -mp.messaging.incoming.order-status.topic=product-events -mp.messaging.incoming.order-status.value.deserializer=org.apache.kafka.common.serialization.StringDeserializer \ No newline at end of file + + +mp.messaging.incoming.order-status-update.connector=smallrye-kafka +mp.messaging.incoming.order-status-update.topic=order-status-update +mp.messaging.incoming.order-status-update.value.deserializer=org.apache.kafka.common.serialization.StringDeserializer \ No newline at end of file