Skip to content

Commit

Permalink
add pricingEvent for the pricing microservice and correct the placing…
Browse files Browse the repository at this point in the history
… of category in product-events
  • Loading branch information
rania1231 committed Dec 27, 2024
1 parent cb69e31 commit 8975f7e
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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();
}
}*/

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -26,6 +27,12 @@ public class EventProducerService {
@Channel("product-availability")
Emitter<String> disponibiltyEventEmitter;


//This event will send only the id to the topic (for the pricing microservice)
@Inject
@Channel("product-created-id")
Emitter<String> pricingEventEmitter;

@PostPersist
public void sendProductEvent(Product product, String eventType) throws JsonProcessingException {
ProductEvent productEvent = new ProductEvent(
Expand Down Expand Up @@ -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();
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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


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

0 comments on commit 8975f7e

Please sign in to comment.