TheBootifulMicroservice
Speaker:JoshLong(Pivotal)
Format:Conférence
Date:22avril2016
Présentation:http://github.com/joshlong/bootiful-microservices
JoshestauteurdulivreCloudNativeJavaetJavaChampion.
Ilaécrit5livresetpleindebugsJ
IltravaillechezPivotaletcontribueàRedis,Spring.IO,CloudFoundry,Tomcat,RabbitMQ
Danscemonde,ilfautallervitesionneveutpassefairedisrupter.Ilsonttuéla
compétition.Uber,Airbnb,Tesla,Booking,Netflix…
Ledéveloppeurdoitseconcentrersurunepetitepartiedutravail=>microservice.
Anotreniveau,Joshconseilled’utiliserlesmicro-servicespourdedévelopperrapidementet
nonpaspourabsorberlachargedeGoogle.500lignesd’instructionssurunepagewikine
permettentpasd’allervite!
SpringBootetSpringCloudpermettentd’allervite.Joshnousleprouveaucoursdecette
conférenceenenchaînantledéveloppementdememicro-servicesenlivecoding.
Plateformestart.spring.io:
Permetdecréerrapidementuneapplicationderéservationaveclestechnos:web,H2,JPA,
Actuator,ConfigClient,Eureka,StreamRabbit,RestRepositories.
Ily’atrèslongtemps,ondevaitutiliserlepackagingWAR.En2016,onchoisitleJAR.
«makejarnotwar»
Téléchargeunzipetl’importedansIntelliJ.
ClasseReservation:uneentitéJPA.
InterfaceSpringDataJPA:ReservationRepositoryannotéeavec@RepositoryRestResource
@ComponentDummyCLRquiimplémenteCommmandLineRunner(joke:déclarerles
attributsdedépendancesfinalpournepastuerunTU).Danslaméthoderun,onalimentela
basededonnéesenmémoire.
LesdonnéessontdéjàdisponiblesenRESTetHATEOS.
Générationdepuisstart.spring.iod’unconfig-service.
Permetd’avoirunserveurquigèrelaconfig.Lesmicroservicesvontpouvoirseconnecterà
ceservicedeconfigurationàlaplacederécupérerlesdonnéesdansapplication.properties.
Dansl’applicationderéservation,créerunfichierbootstrap.propertiescontenantles
paramèresdeconnexionauconfigservice.
Annotation@ResfreshScope?
Changementenlived’unmessagedansleconfigservice
AppeldurefreshparunPOSTsurl’applideréservation.
Permetdes’affranchirduDNS.Laconfestencacheetpeutêtrerafraichie.
Créationd’uneureka-servicepourmettreenrelationlesservicesavecleursclients.
Créationd’unclientderéservation.Ceclientpeutêtrelocalisépartout:Heroku,Tesla,
Réfrigérateur…
Utilisationdureverseproxy:@EnableZuulProxy
Surleclient,onutilise@LoadBalancedRestTemplateennemettantpasleDNSmaislenom
duservice:http://reservation-service/reservations.LeLoadbalancingestassuré.�Pourêtrerésistantauxpannes:@EnableCircuitBreaker(NetflixHystrix).Permetdecréer
uneméthodefallbacksileservicederéservationn’estpaslà.
Créationd’unefileRabbitMQpourcréerunenouvelleréservation
@EnableBinding(Source.class)
Côtémicroservice,onutilisele@EnableBinding(Sink.class)(sinkpourinput)etun
@MessageEndpointavecun@SerciceActivator
Créationd’unZikpin-servicepoursuivrelesmessagesdansunearchitecturedistribuéeet
asynchrone(est-cequeDynatracelefait?).
SpringCloudestdéveloppéparTwiter,Netflix,Pivotal.