DIRECTION DES SYSTEMES D’INFORMATION Rendre une application Spring Boot résiliente JDEV 2020 Stéphane Deraco <[email protected] > Spring Boot, Discovery Server et Config Server
DIRECTION DES SYSTEMES D’INFORMATION
Rendre une application Spring Boot résiliente
JDEV 2020
Stéphane Deraco <[email protected]>
Spring Boot, Discovery Server et Config
Server
P 2DIRECTION DES SYSTEMES D’INFORMATION
Agenda
• Une appli web et 1 service• Deux instances du service• Discovery Server• Config Server• Conclusion
0
P 3DIRECTION DES SYSTEMES D’INFORMATION
Architecture initiale
• Spring Boot• Idée : Récupérer la position de l’ISS
• « web » → « position-fetcher » toutes les 5 secondes• « position-fetcher » retourne l’adresse postale de l’ISS• « web » met jour la page web
1
P 4DIRECTION DES SYSTEMES D’INFORMATION
Architecture initiale
• « position-fetcher »
1
P 5DIRECTION DES SYSTEMES D’INFORMATION
Architecture initiale
• « web »• Toutes les 5 secondes, appel du service…
• … avec un RestTemplate
1
P 6DIRECTION DES SYSTEMES D’INFORMATION
Architecture initiale
• « web »• … pour au final mettre à jour la page web avec une WebSocket
1
P 7DIRECTION DES SYSTEMES D’INFORMATION
Architecture initiale1
P 8DIRECTION DES SYSTEMES D’INFORMATION
Plusieurs instances du service de position
• URLs configurées en dur• Manque de souplesse
2
P 9DIRECTION DES SYSTEMES D’INFORMATION
Plusieurs instances du service de position
• Plusieurs solutions• API Gateway• VIP, Load Balancer• Kubernetes• Discovery Server
2
P 10DIRECTION DES SYSTEMES D’INFORMATION
Discovery Server
• Application Spring Boot• Basée sur les projets Netflix
3
� Chaque instance du service s’enregistre sur le DS pour indiquer son nom (son service) et son url
� « web » interroge le DS pour récupérer la liste des urls proposant un service donné
� « web » interroge alors directement une des instances retournées par le DS
P 11DIRECTION DES SYSTEMES D’INFORMATION
Discovery Server3
Discovery Server
P 12DIRECTION DES SYSTEMES D’INFORMATION
Discovery Server3
P 13DIRECTION DES SYSTEMES D’INFORMATION
Discovery Server3
P 14DIRECTION DES SYSTEMES D’INFORMATION
Discovery Server
• Gestion des indisponibilités• Le DS fonctionne par heartbeat
• Si une instance tombe, le DS n’est pas notifié• Au bout d’un certain temps sans heartbeat de l’instance le DS le considère non
disponible et ne la retournera plus• « web » a un cache local des instances (ne pas interroger le DS à
chaque fois)• Même si une instance est sortie du DS, elle peut encore être présente dans le
cache local
• Solution Spring• spring-retry
3
P 15DIRECTION DES SYSTEMES D’INFORMATION
Discovery Server3
P 16DIRECTION DES SYSTEMES D’INFORMATION
Discovery Server
• Plusieurs instances du services• Ajout et suppression dynamique
• Comment s’assurer que la configuration de chaque instance est la même ?
3
P 17DIRECTION DES SYSTEMES D’INFORMATION
Config Server
• Problème : N instances avec toutes la même configuration
• Si fichiers de conf gérés manuellement, risques d’erreur
• Solutions possibles• Déployer les instances avec Ansible• Config Server• Mode Config First
• Les instances récupèrent l’emplacement du DS dans la config via le CS
• Mode Discovery First• Les instances interrogent le DS pour connaitre l’emplacement du CS
4
P 18DIRECTION DES SYSTEMES D’INFORMATION
Config Server
• Application Spring Boot
4
� Le CS s’enregistre sur le DS� Les services interrogent le DS pour connaitre l’adresse du CS� Les services interrogent le CS pour obtenir leur configuration
�bis Le CS récupère la configuration du service via Git
� Les services s’enregistrent sur le DS� Interrogation du DS pour avoir les URLsdes services� Appel du service
P 19DIRECTION DES SYSTEMES D’INFORMATION
Conclusion
• Fonctionnalités Spring « Cloud »• Discovery• Config• Beaucoup d’autres projets https://spring.io/projects/spring-cloud
• Pour aller plus loin• Cluster de DS et CS• Authentification et autorisation des appels au DS et CS (Spring Security)
• À utiliser si adapté au besoin, à l’infra, aux compétences existantes, …
• Cluster K8S en place ?• Hashicorp Consul déjà utilisé ?• Déploiement via Ansible ?
• Code source• https://forge.git.cnrs.fr/jdev2020
5
P 20DIRECTION DES SYSTEMES D’INFORMATION
Merci de votre attention5
Ressources et crédits
Emplacement ISSEn direct : https://www.esa.int/Science_Exploration/Human_and_Robotic_Exploration/International_Space_Station/Where_is_the_International_Space_Station
Latitude et longitude : API de https://wheretheiss.at/w/developer
Reverse Geo IP : https://nominatim.openstreetmap.org/ (basé sur OpenStreetMap)
Spring BootGuide Service Registration and Discovery : https://spring.io/guides/gs/service-registration-and-discovery/
Guide Centralized Configuration : https://spring.io/guides/gs/centralized-configuration/
Doc : Spring Cloud Netflix : https://cloud.spring.io/spring-cloud-netflix/2.2.x/reference/html/
Doc : Spring Cloud Config : https://cloud.spring.io/spring-cloud-static/spring-cloud-config/2.2.3.RELEASE/reference/html/