- Membre 1 : Abdelmoumene youssef
- Membre 2 : Merouania Aiman
- Groupe : 5IIR11 G2
Ce projet est une implémentation complète d'une architecture microservices pour le devoir de JEE. Il démontre l'utilisation de Spring Cloud Config, Eureka, Gateway, OpenFeign, Resilience4j, et Spring Cloud LoadBalancer.
Le système est composé de 6 modules Maven :
graph TD
User[Client / Postman] --> Gateway[Gateway Server :8080]
Gateway --> |lb://microservice-commandes-v1| MS_Cmd_V1[Commandes V1 :8081 / :8084...]
Gateway --> |lb://microservice-commandes-v2| MS_Cmd_V2[Commandes V2 :8083]
Gateway --> |lb://microservice-produit| MS_Prod[Produit :8082]
MS_Cmd_V1 -.-> Config[Config Server :8888]
MS_Cmd_V2 -.-> Config
MS_Prod -.-> Config
Gateway -.-> Config
MS_Cmd_V1 -.-> Eureka[Eureka Server :8761]
MS_Cmd_V2 -.-> Eureka
MS_Prod -.-> Eureka
Gateway -.-> Eureka
MS_Cmd_V2 --> |Feign + Resilience4j| MS_Prod
-
config-server (
:8888): Serveur de configuration centralisée (profilnativepointant versC:/JEE_micro/config-repo). -
eureka-server (
:8761): Serveur de découverte de services (Service Registry). -
gateway-server (
:8080): Point d'entrée unique. Route les requêtes vers les microservices. -
microservice-commandes-v1 (
:8081): Service de gestion des commandes (indépendant).- Feature: Config dynamique
@RefreshScope, Health Check personnalisé.
- Feature: Config dynamique
-
microservice-produit (
:8082): Service de gestion des produits.- Feature: Simulation de latence pour tester le Circuit Breaker.
-
microservice-commandes-v2 (
:8083): Version 2 des commandes.- Feature: Appelle
microservice-produitvia Feign. Protégé par Resilience4j (fallback).
- Feature: Appelle
- Java 17
- Maven
A la racine du projet (C:\JEE_micro), exécutez :
mvn clean install -DskipTestsOuvrez 5 ou 6 terminaux séparés et lancez les commandes suivantes dans l'ordre :
Terminal 1 : Config Server
cd config-server
mvn spring-boot:runAttendre que le serveur démarre sur le port 8888.
Terminal 2 : Eureka Server
cd eureka-server
mvn spring-boot:runAttendre que le serveur démarre sur le port 8761.
Terminal 3 : Microservice Produit
cd microservice-produit
mvn spring-boot:runTerminal 4 : Microservice Commandes V1 (Instance 1)
cd microservice-commandes-v1
mvn spring-boot:runTerminal 5 : Microservice Commandes V2
cd microservice-commandes-v2
mvn spring-boot:runTerminal 6 : Gateway Server
cd gateway-server
mvn spring-boot:runPour tester le load balancing, lancez une deuxième instance de microservice-commandes-v1 sur un autre port (ex: 8084)
Terminal 7 (Autre instance)
cd microservice-commandes-v1
mvn spring-boot:run -Dspring-boot.run.arguments="--server.port=8084"Chaque microservice expose sa documentation OpenAPI :
- Commandes V1 : http://localhost:8081/swagger-ui/index.html
- Produit : http://localhost:8082/swagger-ui/index.html
- Commandes V2 : http://localhost:8083/swagger-ui/index.html
# Accès via Gateway -> Commandes V1
curl http://localhost:8080/api/v1/commandes
# Accès via Gateway -> Produit
curl http://localhost:8080/api/produitsAppelez plusieurs fois l'endpoint /info via la Gateway. Vous devriez voir les ports alterner (8081, 8084...) si vous avez lancé 2 instances.
curl http://localhost:8080/api/v1/commandes/info
curl http://localhost:8080/api/v1/commandes/infoVérifier la valeur actuelle (défaut 10) :
curl http://localhost:8080/api/v1/commandes/recentModifier le fichier C:\JEE_micro\config-repo\microservice-commandes-v1.yml (mettre commandes-last: 20), puis rafraîchir :
# POST sur l'actuator de l'instance (ou via gateway si configuré, ici direct sur service pour sureté)
curl -X POST http://localhost:8081/actuator/refreshLe service V2 appelle Produit. Si Produit est lent (endpoint /slow), le fallback s'active.
Test appel normal :
curl http://localhost:8080/api/v2/commandes/1Pour tester le circuit breaker, il faudrait modifier le code pour appeler /slow ou simplement éteindre le service Produit.
Le code actuel de V2 appelle getProduitById. Si vous éteignez microservice-produit, V2 répondra quand même avec le produit "Fallback".
Arrêtez le service produit (CTRL+C dans Terminal 3) et réessayez :
curl http://localhost:8080/api/v2/commandes/1Réponse attendue : Produit avec nom "Produit non disponible (Fallback)".
curl http://localhost:8081/actuator/healthNote: Les fichiers de configuration centralisée sont situés dans C:\JEE_micro\config-repo.