Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Arquitecturas de microservicios - Medianet Software

1,617 views

Published on

Arquitecturas de microservicios con Spring Cloud - Netflix OSS

Published in: Software

Arquitecturas de microservicios - Medianet Software

  1. 1. Arquitecturas de Microservicios Ernesto Hernández Rodríguez Arquitecto Java en Medianet Software @ehdez73
  2. 2. ¿MicroServicios?
  3. 3. "Microservices is a software architecture design pattern, in which complex applications are composed of small, independent processes communicating with each other using language-agnostic APIs. These services are small, highly decoupled and focus on doing a small task."
  4. 4. Evolución arquitectura
  5. 5. Beneficios ∘ Servicios pequeños ∘ Principio de responsabilidad única ∘ Fácilmente abarcable ∘ Políglota ∘ PoC ∘ Despliegues ∘ Escalado eficiente
  6. 6. BUT… WAIT A MOMENT!
  7. 7. Nuevos desafíos ∘ ¿Cómo localizo los servicios? ∘ ¿Qué pasa si alguno falla? ∘ ¿Cómo los configuro? ∘ ¿Y las trazas? ∘ ¿Y los diferentes entornos?
  8. 8. Necesitamos
  9. 9. http://screenagers.me/wp-content/uploads/2012/01/US-bandwidth.png
  10. 10. EUREKA ARCHAIUS HYSTRIX TURBINE ZUUL BLITZ4J RIBBON http://netflix.github.io
  11. 11. EUREKA Service locator ∘ API REST ∘ Eureka Server - Peer awarness ∘ Eureka Client - Service Discovery https://github.com/Netflix/eureka
  12. 12. ARCHAIUS Configuration management ∘ Apache Commons Configuration ∘ Configuration Source ∘ High throughput ∘ Thread safe ∘ Composite configuration ∘ JMX https://github.com/Netflix/Archaius
  13. 13. RIBBON Interprocess communication ∘ Balanceador de carga ∘ Cliente Eureka ∘ Hystrix https://github.com/Netflix/Ribbon
  14. 14. HYSTRIX Circuit Breaker ∘ Aislar puntos de acceso ∘ Tolerancia a fallos ∘ Fallos en cascada ∘ Dashboard https://github.com/Netflix/Hystrix
  15. 15. http://cloud.spring.io/spring-cloud-netflix/images/HystrixGraph.png Circuit Breaker
  16. 16. Circuit Breaker http://cloud.spring.io/spring-cloud-netflix/images/HystrixFallback.png
  17. 17. Hystrix Dashboard http://techblog.netflix.com/2012/12/hystrix-dashboard-and-turbine.html
  18. 18. TURBINE Stream aggregator Turbine is an application that aggregates all of the relevant /hystrix.stream endpoints into a combined /turbine.stream for use in the Hystrix Dashboard https://github.com/Netflix/Turbine
  19. 19. http://youtu.be/zWM7oAbVL4g
  20. 20. ZUUL Edge Service ∘ Router and filter ∘ Reverse proxy ∘ Ribbon & Eureka ∘ Hystrix https://github.com/Netflix/Zuul
  21. 21. BLITZ4J Fast asynchronous logging ∘ Basado en log4j ∘ Menos recursos ∘ Más rápido ∘ Archaius https://github.com/Netflix/Blitz4j
  22. 22. CorrelationID http://ragavj.blogspot.com.es/2013/08/how-to-lookup-error-in-sharepoint-2010.html
  23. 23. ELK STACK Files Logstash ElasticSearch Kibana
  24. 24. Spring Cloud https://github.com/spring-cloud
  25. 25. Eureka Server @Configuration @EnableAutoConfiguration @EnableEurekaServer public class Application { public static void main(String[] args) { new SpringApplicationBuilder(Application.class) .web(true) .run(args); } }
  26. 26. Eureka Server @Configuration @EnableAutoConfiguration @EnableEurekaServer public class Application { application.yml server: port: 8761 eureka: instance: public static void main(String[] args) { hostname: localhost client: registerWithEureka: false fetchRegistry: false serviceUrl: new SpringApplicationBuilder(Application.class) .web(true) .run(args); } } defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
  27. 27. Eureka Client @Configuration @ComponentScan @EnableAutoConfiguration @EnableEurekaClient @RestController public class Application { @RequestMapping("/") public String home() { return "Hello world"; } public static void main(String[] args) { new SpringApplicationBuilder(Application.class) .web(true).run(args); } }
  28. 28. Eureka Client @Configuration @ComponentScan @EnableAutoConfiguration @EnableEurekaClient @RestController public class Application { @RequestMapping("/") public String home() { return "Hello world"; } public static void main(String[] args) { new SpringApplicationBuilder(Application.class) .web(true).run(args); } } application.yml eureka: client: serviceUrl: defaultZone: http://localhost:8761/eureka/
  29. 29. Ribbon Transparente vía RestTemplate RibbonAutoConfiguration.java @Bean @ConditionalOnMissingBean(RestTemplate.class) public RestTemplate restTemplate(RibbonInterceptor ribbonInterceptor) { RestTemplate restTemplate = new RestTemplate(); List<ClientHttpRequestInterceptor> list = new ArrayList<>(); list.add(ribbonInterceptor); restTemplate.setInterceptors(list); return restTemplate; } } http://github.com/.../RibbonAutoConfiguration.java
  30. 30. Hystrix wrapper @Component public class StoreIntegration { @HystrixCommand(fallbackMethod = "defaultStores") public Object getStores(Map<String, Object> parameters) { //do stuff that might fail } public Object defaultStores(Map<String, Object> parameters) { return /* something useful */; } }
  31. 31. Hystrix Config @Configuration @EnableAutoConfiguration @EnableHystrix @EnableHystrixDashboard @ComponentScan public class Application { public static void main(String[] args) { new SpringApplicationBuilder(Application.class) .web(true) .run(args); } }
  32. 32. Zuul Config @EnableZuulProxy zuul.proxy.mapping: /api zuul.proxy.route.users: /users /api/users → /users Hystrix → Ribbon → Eureka
  33. 33. Spring Cloud Config ∘ Properties en repositorio Git ∘ API ∘ Profiles ∘ Encriptado ∘ @RefreshScope ∘ PropertySource & Env https://github.com/spring-cloud/spring-cloud-config
  34. 34. Spring Cloud Config - Server @Configuration @EnableAutoConfiguration @EnableEurekaClient @EnableConfigServer public class ConfigServerApplication { public static void main(String[] args) { SpringApplication.run(ConfigServerApplication.class, args); } }
  35. 35. Spring Cloud Config - Server @Configuration @EnableAutoConfiguration @EnableEurekaClient @EnableConfigServer public class ConfigServerApplication { public static void main(String[] args) { SpringApplication.run(ConfigServerApplication.class, args); } } bootstrap.yml spring: application: name: configserver encrypt: keyStore: location: classpath:keystore.jks password: ${KEYSTORE_PASSWORD} # foobar alias: test application.yml spring: cloud: config: server: basedir: target/config uri: https://github.com/ehdez73/cloud-config security: user: password: '{cipher}AQBunH7b87s86E='
  36. 36. Spring Cloud Config - Client @Configuration @EnableAutoConfiguration @RestController public class Application { @RequestMapping("/") public String home() { return "Hello world"; } public static void main(String[] args) { new SpringApplicationBuilder(Application.class) .web(true) .run(args); } }
  37. 37. Spring Cloud Config - Client @Configuration @EnableAutoConfiguration @RestController public class Application { @RequestMapping("/") public String home() { return "Hello world"; } public static void main(String[] args) { new SpringApplicationBuilder(Application.class) .web(true) .run(args); } } bootstrap.yml spring: cloud: config: uri: http://localhost:${config.port:8888}
  38. 38. DevOps
  39. 39. https://www.docker.com/whatisdocker/
  40. 40. Dockerfile FROM dockerfile/java MANTAINER Ernesto Hdez, ehdez73@gmail.com ADD target/myapp1.jar /tmp/myapp1.jar EXPOSE 8080 ENTRYPOINT ["java", "-jar", "/tmp/myapp1.jar"] $ mvn package $ docker build -t ehdez73/myapp1 . $ docker run -d -p 8080:8080 --name="m1" ehdez73/myapp1 $ docker ps $ docker stop m1 $ docker start m1 https://registry.hub.docker.com/u/dockerfile/java/dockerfile/
  41. 41. http://www.fig.sh/
  42. 42. Fig.sh
  43. 43. fig.yml myapp1: build: . ports: - "8880:8880" myapp2: image: ehdez73/myapp2 ports: - "8881:8881" links: - db db: image: postgres http://www.fig.sh/yml.html $ fig up
  44. 44. DEMO
  45. 45. MINIONIZE THE WORLD !!! Minions ipsum tulaliloo potatoooo pepete jeje baboiii poulet tikka masala chasy la bodaaa butt. La bodaaa aaaaaah tulaliloo wiiiii la bodaaa la bodaaa belloo! Tulaliloo para tú belloo! Me want bananaaa! Para tú aaaaaah bananaaaa para tú jiji po kass. Potatoooo tulaliloo potatoooo chasy me want bananaaa! Ti aamoo! para tú. https://github.com/ehdez73/minionize-the-world The minions
  46. 46. Muchas gracias @ehdez73

×