-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2a91d53
commit 8a88ac5
Showing
7 changed files
with
144 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package org.soa.dto; | ||
|
||
public class PriceEvent { | ||
private String productId; | ||
private double price; | ||
|
||
// Getters et setters | ||
public String getProductId() { | ||
return productId; | ||
} | ||
|
||
public void setProductId(String productId) { | ||
this.productId = productId; | ||
} | ||
|
||
public double getPrice() { | ||
return price; | ||
} | ||
|
||
public void setPrice(double price) { | ||
this.price = price; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "PriceEvent{" + | ||
"productId='" + productId + '\'' + | ||
", price=" + price + | ||
'}'; | ||
} | ||
} | ||
|
31 changes: 31 additions & 0 deletions
31
cart/src/main/java/org/soa/messaging/PricingEventConsumer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package org.soa.messaging; | ||
|
||
import org.eclipse.microprofile.reactive.messaging.Incoming; | ||
import jakarta.enterprise.context.ApplicationScoped; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.UUID; | ||
|
||
import org.soa.dto.PriceEvent; | ||
|
||
@ApplicationScoped | ||
public class PricingEventConsumer { | ||
|
||
private final Map<UUID, Double> productPrices = new HashMap<>(); // Utilisation de UUID comme clé | ||
|
||
@Incoming("pricing-price-channel") // Le canal Kafka configuré dans application.properties | ||
public void consumePriceEvent(PriceEvent priceEvent) { | ||
// Enregistrer le prix de l'article avec l'UUID comme clé | ||
UUID productId = UUID.fromString(priceEvent.getProductId()); // Conversion de String en UUID | ||
productPrices.put(productId, priceEvent.getPrice()); | ||
System.out.println("Prix reçu pour l'article : " + priceEvent); | ||
} | ||
|
||
public double getPrice(UUID productId) { | ||
return productPrices.getOrDefault(productId, -1.0); // Retourne -1.0 si le produit n'est pas trouvé | ||
} | ||
|
||
public Map<UUID, Double> getAllPrices() { | ||
return productPrices; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
cart/src/main/java/org/soa/serialization/CartDTOSerializer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package org.soa.serialization; | ||
|
||
import io.quarkus.kafka.client.serialization.ObjectMapperSerializer; | ||
import org.soa.dto.CartDTO; | ||
|
||
public class CartDTOSerializer extends ObjectMapperSerializer<CartDTO> { | ||
|
||
/** | ||
* Constructor for CartDTOSerializer. | ||
* This ensures the ObjectMapper provided by Quarkus is used to serialize CartDTO objects. | ||
*/ | ||
public CartDTOSerializer() { | ||
super(); | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
cart/src/main/java/org/soa/serialization/PriceEventDeserializer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package org.soa.serialization; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import org.apache.kafka.common.serialization.Deserializer; | ||
|
||
import java.util.Map; | ||
import org.soa.dto.PriceEvent; | ||
|
||
|
||
public class PriceEventDeserializer implements Deserializer<PriceEvent> { | ||
|
||
private final ObjectMapper objectMapper = new ObjectMapper(); | ||
|
||
@Override | ||
public void configure(Map<String, ?> configs, boolean isKey) { | ||
// Configuration si nécessaire | ||
} | ||
|
||
@Override | ||
public PriceEvent deserialize(String topic, byte[] data) { | ||
try { | ||
return objectMapper.readValue(data, PriceEvent.class); | ||
} catch (Exception e) { | ||
throw new RuntimeException("Erreur lors de la désérialisation de l'événement de prix", e); | ||
} | ||
} | ||
|
||
@Override | ||
public void close() { | ||
// Nettoyage si nécessaire | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters