SlideShare ist ein Scribd-Unternehmen logo
1 von 11
Downloaden Sie, um offline zu lesen
Industrialisation des contrats d’interface
Centraliser les contrats avec Netflix/Feign
Quoi ? Netflix c’est fait pour se détendre devant une série non ?
Par Idriss Neumann, le 09/05/2016
Sommaire
❖ Vous avez dit “centraliser” ?
➢
➢
❖ Utilisation de Feign
➢
➢
➢
➢
➢
❖ Stratégie de migration des appels RestTemplate vers
Feign
❖ Conclusion / Questions
Vous avez dit centraliser ?
Analyse d’impact simplifiée
❖
❖
❖
Vous avez dit centraliser ?
Simplification de la gestion des dépendances / micros-jars
Vous avez dit centraliser ?
Simplification de la gestion des dépendances / micros-jars
Utilisation de Feign
Pourquoi Feign ?
❖
❖
❖
❖
Utilisation de Feign
Créer un contrat d’interface
// Version Jax-rs
@Path(“/v1/users”)
public interface UserService {
@GET
@Path(“/{id}”)
User getById(@PathParam("id") String id);
@POST
@Path(“/”)
User create(User user);
@PUT
@Path(“/{id}”)
void update(@PathParam(“id”), User user);
@DELETE
@Path(“/{id}”)
void delete(@PathParam(“id”));
}
// Version Feign
public interface UserService {
@RequestLine(“GET /v1/users/{id}”)
@Headers("accept: text/xml")
User getById(@Param("id") String id);
@RequestLine(“GET {href}”)
@Headers("accept: text/xml")
User getByHref(@Param("href") String href);
@RequestLine(“GET /v1/users/?email={email}”)
User getByEmail(@Param("email") String email);
@RequestLine(“DELETE /v1/users/{id}”)
@Headers("Authorization: Bearer {accessToken}")
void delete(Param(“accessToken”) String accessToken);
}
Utilisation de Feign
Créer un client
public class UserClient extends AbstractClient implements UserService {
public UserClient(String url, RequestInterceptor interceptor) {
super(url, interceptor);
// Supposons que l’object mapper Jackson est héritée d’une abstract
feignClient = Feign.builder()
.client(buildHttpClient())
.requestInterceptor(interceptor)
.encoder(new JacksonEncoder(OBJECT_MAPPER))
.decoder(new JacksonDecoder(OBJECT_MAPPER))
.target(UserService.class, url);
// Pour du Jax-rs ajouter .contract(new JAXRSContract())
}
// Implémenter les méthodes et déleguer
}
Utilisation de Feign
Instanciation d’un client dans Spring et utilisation
// Instanciation
@Bean(name = "userServiceClient")
public UserService userService(@Value("${endpoint.url}") String endpoint) {
return new UserClient(endpoint, (RequestInterceptor) requestTemplate -> {
requestTemplate.header(“header_key”, “header_value”);
});
}
// Utilisation
@Autowired
private UserService userService;
// ...
userService.getById(id);
Stratégie de migration des appels RestTemplate vers Feign
❖
❖
❖
❖
❖
❖
❖
❖
❖
❖
❖
Questions

Weitere ähnliche Inhalte

Was ist angesagt?

XebiConFr - 15 - Apache Mesos, ou comment exploiter les ressources de votre d...
XebiConFr - 15 - Apache Mesos, ou comment exploiter les ressources de votre d...XebiConFr - 15 - Apache Mesos, ou comment exploiter les ressources de votre d...
XebiConFr - 15 - Apache Mesos, ou comment exploiter les ressources de votre d...Publicis Sapient Engineering
 
Intégration continue des projets PHP avec Jenkins
Intégration continue des projets PHP avec JenkinsIntégration continue des projets PHP avec Jenkins
Intégration continue des projets PHP avec JenkinsHugo Hamon
 
Introduction à Angularjs
Introduction à AngularjsIntroduction à Angularjs
Introduction à AngularjsRossi Oddet
 
GWT Principes & Techniques
GWT Principes & TechniquesGWT Principes & Techniques
GWT Principes & TechniquesRachid NID SAID
 
Presentation of GWT 2.4 (PowerPoint version)
Presentation of GWT 2.4 (PowerPoint version)Presentation of GWT 2.4 (PowerPoint version)
Presentation of GWT 2.4 (PowerPoint version)Celinio Fernandes
 
Presentation of GWT 2.4 (PDF version)
Presentation of GWT 2.4 (PDF version)Presentation of GWT 2.4 (PDF version)
Presentation of GWT 2.4 (PDF version)Celinio Fernandes
 
DevOps - from idea to production
DevOps - from idea to productionDevOps - from idea to production
DevOps - from idea to productionHabib MAALEM
 
Ces outils qui vous font gagner du temps
Ces outils qui vous font gagner du tempsCes outils qui vous font gagner du temps
Ces outils qui vous font gagner du tempsAntoine Rey
 
Introduction à Angular JS
Introduction à Angular JSIntroduction à Angular JS
Introduction à Angular JSAntoine Rey
 
Les dessous du framework spring
Les dessous du framework springLes dessous du framework spring
Les dessous du framework springAntoine Rey
 
Présentation Rex GWT 2.0
Présentation Rex GWT 2.0Présentation Rex GWT 2.0
Présentation Rex GWT 2.0Ippon
 
Workshop Spring - Session 5 - Spring Integration
Workshop Spring - Session 5 - Spring IntegrationWorkshop Spring - Session 5 - Spring Integration
Workshop Spring - Session 5 - Spring IntegrationAntoine Rey
 
Workshop Spring - Session 4 - Spring Batch
Workshop Spring -  Session 4 - Spring BatchWorkshop Spring -  Session 4 - Spring Batch
Workshop Spring - Session 4 - Spring BatchAntoine Rey
 
Workshop Spring 3 - Tests et techniques avancées du conteneur Spring
Workshop Spring  3 - Tests et techniques avancées du conteneur SpringWorkshop Spring  3 - Tests et techniques avancées du conteneur Spring
Workshop Spring 3 - Tests et techniques avancées du conteneur SpringAntoine Rey
 
Microbox : Ma toolbox microservices - Julien Roy
Microbox : Ma toolbox microservices - Julien RoyMicrobox : Ma toolbox microservices - Julien Roy
Microbox : Ma toolbox microservices - Julien Royekino
 

Was ist angesagt? (20)

XebiConFr - 15 - Apache Mesos, ou comment exploiter les ressources de votre d...
XebiConFr - 15 - Apache Mesos, ou comment exploiter les ressources de votre d...XebiConFr - 15 - Apache Mesos, ou comment exploiter les ressources de votre d...
XebiConFr - 15 - Apache Mesos, ou comment exploiter les ressources de votre d...
 
Intégration continue des projets PHP avec Jenkins
Intégration continue des projets PHP avec JenkinsIntégration continue des projets PHP avec Jenkins
Intégration continue des projets PHP avec Jenkins
 
Introduction à Angularjs
Introduction à AngularjsIntroduction à Angularjs
Introduction à Angularjs
 
GWT Principes & Techniques
GWT Principes & TechniquesGWT Principes & Techniques
GWT Principes & Techniques
 
Presentation of GWT 2.4 (PowerPoint version)
Presentation of GWT 2.4 (PowerPoint version)Presentation of GWT 2.4 (PowerPoint version)
Presentation of GWT 2.4 (PowerPoint version)
 
Presentation of GWT 2.4 (PDF version)
Presentation of GWT 2.4 (PDF version)Presentation of GWT 2.4 (PDF version)
Presentation of GWT 2.4 (PDF version)
 
DevOps - from idea to production
DevOps - from idea to productionDevOps - from idea to production
DevOps - from idea to production
 
Ces outils qui vous font gagner du temps
Ces outils qui vous font gagner du tempsCes outils qui vous font gagner du temps
Ces outils qui vous font gagner du temps
 
Introduction à Angular JS
Introduction à Angular JSIntroduction à Angular JS
Introduction à Angular JS
 
Les dessous du framework spring
Les dessous du framework springLes dessous du framework spring
Les dessous du framework spring
 
Présentation Rex GWT 2.0
Présentation Rex GWT 2.0Présentation Rex GWT 2.0
Présentation Rex GWT 2.0
 
ParisJUG Spring Boot
ParisJUG Spring BootParisJUG Spring Boot
ParisJUG Spring Boot
 
Présentation OSGI
Présentation OSGIPrésentation OSGI
Présentation OSGI
 
Spring & SpringBatch FR
Spring & SpringBatch FRSpring & SpringBatch FR
Spring & SpringBatch FR
 
JENKINS_BreizhJUG_20111003
JENKINS_BreizhJUG_20111003JENKINS_BreizhJUG_20111003
JENKINS_BreizhJUG_20111003
 
Workshop Spring - Session 5 - Spring Integration
Workshop Spring - Session 5 - Spring IntegrationWorkshop Spring - Session 5 - Spring Integration
Workshop Spring - Session 5 - Spring Integration
 
Workshop Spring - Session 4 - Spring Batch
Workshop Spring -  Session 4 - Spring BatchWorkshop Spring -  Session 4 - Spring Batch
Workshop Spring - Session 4 - Spring Batch
 
Workshop Spring 3 - Tests et techniques avancées du conteneur Spring
Workshop Spring  3 - Tests et techniques avancées du conteneur SpringWorkshop Spring  3 - Tests et techniques avancées du conteneur Spring
Workshop Spring 3 - Tests et techniques avancées du conteneur Spring
 
Microbox : Ma toolbox microservices - Julien Roy
Microbox : Ma toolbox microservices - Julien RoyMicrobox : Ma toolbox microservices - Julien Roy
Microbox : Ma toolbox microservices - Julien Roy
 
Elsass JUG - OSGi
Elsass JUG - OSGiElsass JUG - OSGi
Elsass JUG - OSGi
 

Andere mochten auch

Using the restful twitter’s api
Using the restful twitter’s apiUsing the restful twitter’s api
Using the restful twitter’s apiIdriss Neumann
 
MapStruct - der neue Stern am Bean-Mapping Himmel?!
MapStruct - der neue Stern am Bean-Mapping Himmel?!MapStruct - der neue Stern am Bean-Mapping Himmel?!
MapStruct - der neue Stern am Bean-Mapping Himmel?!inovex GmbH
 
Spring Framework Petclinic sample application
Spring Framework Petclinic sample applicationSpring Framework Petclinic sample application
Spring Framework Petclinic sample applicationAntoine Rey
 
Introduction à spring boot
Introduction à spring bootIntroduction à spring boot
Introduction à spring bootAntoine Rey
 
Les 7 raisons pour lesquelles tout le monde veut travailler chez Netflix
Les 7 raisons pour lesquelles tout le monde veut travailler chez NetflixLes 7 raisons pour lesquelles tout le monde veut travailler chez Netflix
Les 7 raisons pour lesquelles tout le monde veut travailler chez NetflixArkadin France
 
Retours Devoxx France 2016
Retours Devoxx France 2016Retours Devoxx France 2016
Retours Devoxx France 2016Antoine Rey
 
Tester unitairement une application java
Tester unitairement une application javaTester unitairement une application java
Tester unitairement une application javaAntoine Rey
 

Andere mochten auch (7)

Using the restful twitter’s api
Using the restful twitter’s apiUsing the restful twitter’s api
Using the restful twitter’s api
 
MapStruct - der neue Stern am Bean-Mapping Himmel?!
MapStruct - der neue Stern am Bean-Mapping Himmel?!MapStruct - der neue Stern am Bean-Mapping Himmel?!
MapStruct - der neue Stern am Bean-Mapping Himmel?!
 
Spring Framework Petclinic sample application
Spring Framework Petclinic sample applicationSpring Framework Petclinic sample application
Spring Framework Petclinic sample application
 
Introduction à spring boot
Introduction à spring bootIntroduction à spring boot
Introduction à spring boot
 
Les 7 raisons pour lesquelles tout le monde veut travailler chez Netflix
Les 7 raisons pour lesquelles tout le monde veut travailler chez NetflixLes 7 raisons pour lesquelles tout le monde veut travailler chez Netflix
Les 7 raisons pour lesquelles tout le monde veut travailler chez Netflix
 
Retours Devoxx France 2016
Retours Devoxx France 2016Retours Devoxx France 2016
Retours Devoxx France 2016
 
Tester unitairement une application java
Tester unitairement une application javaTester unitairement une application java
Tester unitairement une application java
 

Ähnlich wie Industrialisation des contrats d'interface avec netflix feign

DevOps : mission [im]possible ?
DevOps : mission [im]possible ?DevOps : mission [im]possible ?
DevOps : mission [im]possible ?rfelden
 
Introduction to WebRTC on iOS
Introduction to WebRTC on iOSIntroduction to WebRTC on iOS
Introduction to WebRTC on iOSCocoaHeads France
 
One version to rules them all
One version to rules them allOne version to rules them all
One version to rules them allpinguin666
 
1er Meetup Mobile Montpellier - Présentation Appcelerator Titanium - Alloy
1er Meetup Mobile Montpellier - Présentation Appcelerator Titanium - Alloy1er Meetup Mobile Montpellier - Présentation Appcelerator Titanium - Alloy
1er Meetup Mobile Montpellier - Présentation Appcelerator Titanium - AlloyMeetup Mobile Montpellier
 
Publier une application mobile en un clic
Publier une application mobile en un clicPublier une application mobile en un clic
Publier une application mobile en un clicFabernovel
 
PresentationFlutter4hghghhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh.pdf
PresentationFlutter4hghghhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh.pdfPresentationFlutter4hghghhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh.pdf
PresentationFlutter4hghghhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh.pdfzoulaikhibenaachourn
 
Rapport de stage FRANK FAPONG Encadreur - Kamleu Noumi Emeric.pdf
Rapport de stage FRANK FAPONG Encadreur - Kamleu Noumi Emeric.pdfRapport de stage FRANK FAPONG Encadreur - Kamleu Noumi Emeric.pdf
Rapport de stage FRANK FAPONG Encadreur - Kamleu Noumi Emeric.pdfEmeric Kamleu Noumi
 
Ce qu'il faut retenir de la FrenchKit iOS
Ce qu'il faut retenir de la FrenchKit iOSCe qu'il faut retenir de la FrenchKit iOS
Ce qu'il faut retenir de la FrenchKit iOSNiji
 
La Duck Conf - DevOps et Dataviz, un amour impossible ?
La Duck Conf - DevOps et Dataviz, un amour impossible ? La Duck Conf - DevOps et Dataviz, un amour impossible ?
La Duck Conf - DevOps et Dataviz, un amour impossible ? OCTO Technology
 
Gab17 lyon-rex build dev ops sur une infra iaas-paas multisite-by-matthieupetite
Gab17 lyon-rex build dev ops sur une infra iaas-paas multisite-by-matthieupetiteGab17 lyon-rex build dev ops sur une infra iaas-paas multisite-by-matthieupetite
Gab17 lyon-rex build dev ops sur une infra iaas-paas multisite-by-matthieupetiteAZUG FR
 
Géolocalisation, Speech, Intégration : Tirez parti des nouveautés de Windows ...
Géolocalisation, Speech, Intégration : Tirez parti des nouveautés de Windows ...Géolocalisation, Speech, Intégration : Tirez parti des nouveautés de Windows ...
Géolocalisation, Speech, Intégration : Tirez parti des nouveautés de Windows ...Microsoft
 
Initiation Webperf : Comprendre, analyser et optimiser les performances web F...
Initiation Webperf : Comprendre, analyser et optimiser les performances web F...Initiation Webperf : Comprendre, analyser et optimiser les performances web F...
Initiation Webperf : Comprendre, analyser et optimiser les performances web F...Kenny Dits
 
RMLL_2011_icinga_un_fork_de_nagios_core.odp
RMLL_2011_icinga_un_fork_de_nagios_core.odpRMLL_2011_icinga_un_fork_de_nagios_core.odp
RMLL_2011_icinga_un_fork_de_nagios_core.odpCharles JUDITH
 
Intégration continue & Qualité logicielle
Intégration continue & Qualité logicielleIntégration continue & Qualité logicielle
Intégration continue & Qualité logicielleDavid Buros
 
20090615 - Ch'ti JUG - Apache Maven
20090615 - Ch'ti JUG - Apache Maven20090615 - Ch'ti JUG - Apache Maven
20090615 - Ch'ti JUG - Apache MavenArnaud Héritier
 
Nuxeo Summer Seminar 2007 - Vision And Market (FR)
Nuxeo  Summer Seminar 2007 - Vision And Market (FR)Nuxeo  Summer Seminar 2007 - Vision And Market (FR)
Nuxeo Summer Seminar 2007 - Vision And Market (FR)Stefane Fermigier
 
Windows Phone: Migrez de Silverlight vers Universal App, Préparez vous à Wind...
Windows Phone: Migrez de Silverlight vers Universal App, Préparez vous à Wind...Windows Phone: Migrez de Silverlight vers Universal App, Préparez vous à Wind...
Windows Phone: Migrez de Silverlight vers Universal App, Préparez vous à Wind...Microsoft
 
Retour d'expérience sur DirectAccess, bonnes pratiques, dépannage
Retour d'expérience sur DirectAccess, bonnes pratiques, dépannageRetour d'expérience sur DirectAccess, bonnes pratiques, dépannage
Retour d'expérience sur DirectAccess, bonnes pratiques, dépannageMicrosoft Technet France
 
20171122 01 - REX : Intégration et déploiement continu chez Engie
20171122 01 - REX : Intégration et déploiement continu chez Engie20171122 01 - REX : Intégration et déploiement continu chez Engie
20171122 01 - REX : Intégration et déploiement continu chez EngieLeClubQualiteLogicielle
 

Ähnlich wie Industrialisation des contrats d'interface avec netflix feign (20)

DevOps : mission [im]possible ?
DevOps : mission [im]possible ?DevOps : mission [im]possible ?
DevOps : mission [im]possible ?
 
Introduction to WebRTC on iOS
Introduction to WebRTC on iOSIntroduction to WebRTC on iOS
Introduction to WebRTC on iOS
 
One version to rules them all
One version to rules them allOne version to rules them all
One version to rules them all
 
1er Meetup Mobile Montpellier - Présentation Appcelerator Titanium - Alloy
1er Meetup Mobile Montpellier - Présentation Appcelerator Titanium - Alloy1er Meetup Mobile Montpellier - Présentation Appcelerator Titanium - Alloy
1er Meetup Mobile Montpellier - Présentation Appcelerator Titanium - Alloy
 
Publier une application mobile en un clic
Publier une application mobile en un clicPublier une application mobile en un clic
Publier une application mobile en un clic
 
PresentationFlutter4hghghhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh.pdf
PresentationFlutter4hghghhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh.pdfPresentationFlutter4hghghhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh.pdf
PresentationFlutter4hghghhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh.pdf
 
Rapport de stage FRANK FAPONG Encadreur - Kamleu Noumi Emeric.pdf
Rapport de stage FRANK FAPONG Encadreur - Kamleu Noumi Emeric.pdfRapport de stage FRANK FAPONG Encadreur - Kamleu Noumi Emeric.pdf
Rapport de stage FRANK FAPONG Encadreur - Kamleu Noumi Emeric.pdf
 
Ce qu'il faut retenir de la FrenchKit iOS
Ce qu'il faut retenir de la FrenchKit iOSCe qu'il faut retenir de la FrenchKit iOS
Ce qu'il faut retenir de la FrenchKit iOS
 
La Duck Conf - DevOps et Dataviz, un amour impossible ?
La Duck Conf - DevOps et Dataviz, un amour impossible ? La Duck Conf - DevOps et Dataviz, un amour impossible ?
La Duck Conf - DevOps et Dataviz, un amour impossible ?
 
Gab17 lyon-rex build dev ops sur une infra iaas-paas multisite-by-matthieupetite
Gab17 lyon-rex build dev ops sur une infra iaas-paas multisite-by-matthieupetiteGab17 lyon-rex build dev ops sur une infra iaas-paas multisite-by-matthieupetite
Gab17 lyon-rex build dev ops sur une infra iaas-paas multisite-by-matthieupetite
 
Géolocalisation, Speech, Intégration : Tirez parti des nouveautés de Windows ...
Géolocalisation, Speech, Intégration : Tirez parti des nouveautés de Windows ...Géolocalisation, Speech, Intégration : Tirez parti des nouveautés de Windows ...
Géolocalisation, Speech, Intégration : Tirez parti des nouveautés de Windows ...
 
Initiation Webperf : Comprendre, analyser et optimiser les performances web F...
Initiation Webperf : Comprendre, analyser et optimiser les performances web F...Initiation Webperf : Comprendre, analyser et optimiser les performances web F...
Initiation Webperf : Comprendre, analyser et optimiser les performances web F...
 
RMLL_2011_icinga_un_fork_de_nagios_core.odp
RMLL_2011_icinga_un_fork_de_nagios_core.odpRMLL_2011_icinga_un_fork_de_nagios_core.odp
RMLL_2011_icinga_un_fork_de_nagios_core.odp
 
Intégration continue & Qualité logicielle
Intégration continue & Qualité logicielleIntégration continue & Qualité logicielle
Intégration continue & Qualité logicielle
 
20090615 - Ch'ti JUG - Apache Maven
20090615 - Ch'ti JUG - Apache Maven20090615 - Ch'ti JUG - Apache Maven
20090615 - Ch'ti JUG - Apache Maven
 
Nuxeo Summer Seminar 2007 - Vision And Market (FR)
Nuxeo  Summer Seminar 2007 - Vision And Market (FR)Nuxeo  Summer Seminar 2007 - Vision And Market (FR)
Nuxeo Summer Seminar 2007 - Vision And Market (FR)
 
Windows Phone: Migrez de Silverlight vers Universal App, Préparez vous à Wind...
Windows Phone: Migrez de Silverlight vers Universal App, Préparez vous à Wind...Windows Phone: Migrez de Silverlight vers Universal App, Préparez vous à Wind...
Windows Phone: Migrez de Silverlight vers Universal App, Préparez vous à Wind...
 
Retour d'expérience sur DirectAccess, bonnes pratiques, dépannage
Retour d'expérience sur DirectAccess, bonnes pratiques, dépannageRetour d'expérience sur DirectAccess, bonnes pratiques, dépannage
Retour d'expérience sur DirectAccess, bonnes pratiques, dépannage
 
20171122 01 - REX : Intégration et déploiement continu chez Engie
20171122 01 - REX : Intégration et déploiement continu chez Engie20171122 01 - REX : Intégration et déploiement continu chez Engie
20171122 01 - REX : Intégration et déploiement continu chez Engie
 
Voip FreeSwitch
Voip FreeSwitchVoip FreeSwitch
Voip FreeSwitch
 

Industrialisation des contrats d'interface avec netflix feign

  • 1. Industrialisation des contrats d’interface Centraliser les contrats avec Netflix/Feign Quoi ? Netflix c’est fait pour se détendre devant une série non ? Par Idriss Neumann, le 09/05/2016
  • 2. Sommaire ❖ Vous avez dit “centraliser” ? ➢ ➢ ❖ Utilisation de Feign ➢ ➢ ➢ ➢ ➢ ❖ Stratégie de migration des appels RestTemplate vers Feign ❖ Conclusion / Questions
  • 3. Vous avez dit centraliser ? Analyse d’impact simplifiée ❖ ❖ ❖
  • 4. Vous avez dit centraliser ? Simplification de la gestion des dépendances / micros-jars
  • 5. Vous avez dit centraliser ? Simplification de la gestion des dépendances / micros-jars
  • 6. Utilisation de Feign Pourquoi Feign ? ❖ ❖ ❖ ❖
  • 7. Utilisation de Feign Créer un contrat d’interface // Version Jax-rs @Path(“/v1/users”) public interface UserService { @GET @Path(“/{id}”) User getById(@PathParam("id") String id); @POST @Path(“/”) User create(User user); @PUT @Path(“/{id}”) void update(@PathParam(“id”), User user); @DELETE @Path(“/{id}”) void delete(@PathParam(“id”)); } // Version Feign public interface UserService { @RequestLine(“GET /v1/users/{id}”) @Headers("accept: text/xml") User getById(@Param("id") String id); @RequestLine(“GET {href}”) @Headers("accept: text/xml") User getByHref(@Param("href") String href); @RequestLine(“GET /v1/users/?email={email}”) User getByEmail(@Param("email") String email); @RequestLine(“DELETE /v1/users/{id}”) @Headers("Authorization: Bearer {accessToken}") void delete(Param(“accessToken”) String accessToken); }
  • 8. Utilisation de Feign Créer un client public class UserClient extends AbstractClient implements UserService { public UserClient(String url, RequestInterceptor interceptor) { super(url, interceptor); // Supposons que l’object mapper Jackson est héritée d’une abstract feignClient = Feign.builder() .client(buildHttpClient()) .requestInterceptor(interceptor) .encoder(new JacksonEncoder(OBJECT_MAPPER)) .decoder(new JacksonDecoder(OBJECT_MAPPER)) .target(UserService.class, url); // Pour du Jax-rs ajouter .contract(new JAXRSContract()) } // Implémenter les méthodes et déleguer }
  • 9. Utilisation de Feign Instanciation d’un client dans Spring et utilisation // Instanciation @Bean(name = "userServiceClient") public UserService userService(@Value("${endpoint.url}") String endpoint) { return new UserClient(endpoint, (RequestInterceptor) requestTemplate -> { requestTemplate.header(“header_key”, “header_value”); }); } // Utilisation @Autowired private UserService userService; // ... userService.getById(id);
  • 10. Stratégie de migration des appels RestTemplate vers Feign ❖ ❖ ❖ ❖ ❖ ❖ ❖ ❖ ❖ ❖ ❖