Se ha denunciado esta presentación.
Utilizamos tu perfil de LinkedIn y tus datos de actividad para personalizar los anuncios y mostrarte publicidad más relevante. Puedes cambiar tus preferencias de publicidad en cualquier momento.

Microservice With Spring Boot and Spring Cloud

Spring Boot and Spring Cloud are an ideal foundation for creating Microservices based on Java. This presentation explains basic concepts of these libraries.

  • Sé el primero en comentar

Microservice With Spring Boot and Spring Cloud

  1. 1. Microservices with
 Spring Boot & Spring Cloud Eberhard Wolff Freelancer / Trainer
  2. 2. What are Microservices?
  3. 3. Eberhard Wolff - @ewolff Micro Services: Definition •  Small •  Independent deployment units •  i.e. processes or VMs •  Any technology •  Any infrastructure •  Include GUI Micro Service Server Micro Service Server
  4. 4. Eberhard Wolff - @ewolff Components Collaborate Micro Service Micro Service Link Data Replication REST Messaging
  5. 5. Eberhard Wolff - @ewolff Infrastructure for Microservices •  Lots of services •  Need infrastructure Easy to create a new project REST integrated Messaging supported Uniform operations
  6. 6. Spring Boot Demo
  7. 7. Eberhard Wolff - @ewolff Easy to Create New Project •  One pom.xml •  …Gradle / Ant •  Very few dependencies •  One plug in •  Versions defined for you
  8. 8. Eberhard Wolff - @ewolff REST Integrated •  Support in Spring MVC •  As we have seen •  Also support for JAX-RS •  Jersey
  9. 9. Eberhard Wolff - @ewolff Messaging Support •  Numerous Spring Boot Starter •  AMQP (RabbitMQ) •  HornetQ (JMS) •  ActiveMQ (JMS, no starter)
  10. 10. Eberhard Wolff - @ewolff Messaging Support •  Spring JMS abstraction •  Message driven POJOs •  Scalable •  Simplify sending JMS •  Can use other libs, too! •  Boot can do everything plain Spring / Java can do
  11. 11. Eberhard Wolff - @ewolff Infrastructure for Microservices •  More services •  Need infrastructure Easy to create a new project REST integrated Messaging supported Simple deployment Uniform operations ✓ ✓ ✓
  12. 12. Spring Boot
 Deploy Demo
  13. 13. Eberhard Wolff - @ewolff Deploy •  Just package everything in an executable JAR •  …or a WAR •  Based on Maven, Ant or Gradle •  Build in configuration (YAML, properties etc.)
  14. 14. Eberhard Wolff - @ewolff Deploy •  Install a basic machine •  Install Java •  Copy over .jar •  Optional: Create application.properties
  15. 15. Eberhard Wolff - @ewolff Infrastructure for Microservices •  More services •  Need infrastructure Easy to create a new project REST integrated Messaging supported Simple deployment Uniform operations ✓ ✓ ✓ ✓
  16. 16. Eberhard Wolff - @ewolff Spring Boot Actuator •  Provide information about the application •  Via http / JSON •  Can be evaluated by monitoring tools etc. •  Another alternative approach to monitoring
  17. 17. Spring Boot
 Actuator Demo
  18. 18. Eberhard Wolff - @ewolff Infrastructure for Microservices •  More services •  Need infrastructure Easy to create a new project REST integrated Messaging supported Simple deployment Uniform operations ✓ ✓ ✓ ✓ ✓
  19. 19. Eberhard Wolff - @ewolff Deploy •  Just package everything in an executable JAR
  20. 20. Eberhard Wolff - @ewolff Deploy •  Just package everything in an executable JAR •  …or a WAR
  21. 21. Eberhard Wolff - @ewolff Spring Cloud
  22. 22. Eberhard Wolff - @ewolff Based on Spring Boot
  23. 23. Eberhard Wolff - @ewolff Spring Cloud •  Spring support for Amazon Web Services •  Connector for Heroku PaaS •  …and Cloud Foundry PaaS •  The rest of Spring Cloud is for Microservices
  24. 24. Eberhard Wolff - @ewolff Coordinating
 Microservices
  25. 25. Eberhard Wolff - @ewolff Microservice Microservice Must find each other
  26. 26. Eberhard Wolff - @ewolff Service Discovery
 Eureka
  27. 27. Eberhard Wolff - @ewolff Why Eureka? •  REST based service registry •  Supports replication •  Caches on the client •  Resilient •  Fast •  …but not consistent •  Foundation for other services
  28. 28. Eberhard Wolff - @ewolff Eureka Client in Spring Cloud •  @EnableDiscoveryClient: generic •  @EnableEurekaClient: more specific •  Dependency to spring-cloud-starter-eureka •  Automatically registers application
  29. 29. Eberhard Wolff - @ewolff application.properties eureka.client.serviceUrl.defaultZone=http://host: 8761/eureka/< eureka.instance.leaseRenewalIntervalInSeconds=5< spring.application.name=catalog< eureka.instance.metadataMap.instanceId=$ {spring.application.name}:${random.value}< eureka.instance.preferIpAddress=true< Eureka server Can include user / password Need unique ID Load balancing Faster updates Docker won’t resolve host names Used for registration In CAPITAL caps
  30. 30. Eberhard Wolff - @ewolff Eureka Server @EnableEurekaServer< @EnableAutoConfiguration< public'class'EurekaApplication'{' < <public'static'void'main(String[]'args)'{' <<SpringApplication.run(EurekaApplication.class,'args);' <}< < }< Add dependency to spring-cloud-starter-eureka-server
  31. 31. Eberhard Wolff - @ewolff
  32. 32. Eberhard Wolff - @ewolff Eureka
 Demo
  33. 33. Eberhard Wolff - @ewolff Microservice Microservice Must find each other Route calls to a service
  34. 34. Eberhard Wolff - @ewolff Zuul
 Routing
  35. 35. Eberhard Wolff - @ewolff Routing •  One URL to the outside •  Internal: Many Microservices •  REST •  Or HTML GUI
  36. 36. Eberhard Wolff - @ewolff Customer Order Catalog Zuul Proxy Automatically maps route to server registered on Eureka i.e. /customer/** to CUSTOMER No configuration Can add filters etc
  37. 37. Eberhard Wolff - @ewolff Zuul Proxy @SpringBootApplication @EnableZuulProxy public class ZuulApplication { public static void main(String[] args) { new SpringApplicationBuilder(ZuulApplication.class). web(true).run(args); } } Enable Zuul Proxy Can change route Also routing to external services possible
  38. 38. Eberhard Wolff - @ewolff lokaler Rechner Vagrant VM eureka zuul customer -app catalog- app order-app 172.17.0.0/16 Netzwerk 8761 8761 8080 8080 18761 18080
  39. 39. Eberhard Wolff - @ewolff Zuul
 Demo
  40. 40. Eberhard Wolff - @ewolff Microservice Microservice Must find each other Configuration Route calls to a service
  41. 41. Eberhard Wolff - @ewolff Configuration •  Spring Cloud Config •  Central configuration •  Dynamic updates •  Can use git backend •  I prefer immutable server •  & DevOps tools (Docher, Chef…)
  42. 42. Eberhard Wolff - @ewolff Microservice Microservice Must find each other Configuration Route calls to a service Communication
  43. 43. Eberhard Wolff - @ewolff Spring Cloud Bus
  44. 44. Eberhard Wolff - @ewolff Spring Cloud Bus •  Pushed config updates •  …or individual message •  I prefer a messaging solution •  Independent from Spring
  45. 45. Eberhard Wolff - @ewolff Microservice Microservice Must find each other Configuration Route calls to a service Communication Security
  46. 46. Eberhard Wolff - @ewolff Spring Cloud Security
  47. 47. Eberhard Wolff - @ewolff Spring Cloud Security •  Single Sign On via OAuth2 •  Forward token e.g. via RestTemplate •  Support for Zuul •  Very valuable!
  48. 48. Eberhard Wolff - @ewolff Implementing
 Microservices
  49. 49. Eberhard Wolff - @ewolff Microservice Microservice Load Balancing
  50. 50. Eberhard Wolff - @ewolff Load Balancing
 Ribbon
  51. 51. Eberhard Wolff - @ewolff Ribbon: Client Side Load Balancing •  Decentralized Load Balancing •  No bottle neck •  Resilient •  Hard to consider metrics / health •  Data might be inconsistent Load Balancer Server Client
  52. 52. Eberhard Wolff - @ewolff RestTemplate & Load Balancing @RibbonClient(name = "ribbonApp") … public class RibbonApp { @Autowired private RestTemplate restTemplate; public void callMicroService() { Store store = restTemplate. getForObject("http://stores/store/1", Store.class); } } Enable Ribbon Left out other annotations Eureka name or server list Standard Spring REST client Can also use Ribbon API
  53. 53. Eberhard Wolff - @ewolff Microservice Microservice Load Balancing Resilience
  54. 54. Eberhard Wolff - @ewolff Hystrix
 Resilience
  55. 55. Eberhard Wolff - @ewolff Hystrix •  Enable resilient applications •  Do call in other thread pool •  Won’t block request handler •  Can implement timeout
  56. 56. Eberhard Wolff - @ewolff Hystrix •  Circuit Breaker •  If call system fail open •  If open do not forward call •  Forward calls after a time window •  System won’t be swamped with requests
  57. 57. Eberhard Wolff - @ewolff Hystrix / Spring Cloud •  Annotation based approach •  Java Proxies automatically created •  Annotations of javanica libraries •  Simplifies Hystrix dramatically •  No commands etc
  58. 58. Eberhard Wolff - @ewolff @HystrixCommand(fallbackMethod = "getItemsCache") public Collection<Item> findAll() { … this.itemsCache = pagedResources.getContent(); return itemsCache; } private Collection<Item> getItemsCache() { return itemsCache; }< Fallback
  59. 59. Eberhard Wolff - @ewolff lokaler Rechner Vagrant VM eureka zuul customer -app catalog- app order-app 172.17.0.0/16 Netzwerk 8761 8761 8080 8080 18761 18080
  60. 60. Eberhard Wolff - @ewolff lokaler Rechner Vagrant VM eureka zuul customer -app catalog- app turbine order-app 172.17.0.0/16 Netzwerk 8761 8761 8989 8989 8080 8080 18761 18989 18080
  61. 61. Eberhard Wolff - @ewolff Hystrix Dashboard Stream via http Circuit Breaker status Thread Pool status
  62. 62. Eberhard Wolff - @ewolff Conclusion
  63. 63. Eberhard Wolff - @ewolff Spring Boot for Microservices Easy to create a new project REST integrated Messaging supported Simple deployment Uniform operations ✓ ✓ ✓ ✓ ✓
  64. 64. Eberhard Wolff - @ewolff Hystrix
 Demo
  65. 65. Eberhard Wolff - @ewolff Must find each other: Service Discovery Configuration Route calls to a service Communication Load Balancing Resilience Spring Cloud for Microservices
  66. 66. Eberhard Wolff - @ewolff Links http://projects.spring.io/spring-boot/ http://projects.spring.io/spring-cloud https://github.com/ewolff/spring-boot-demos https://github.com/ewolff/microservices https://spring.io/guides/
  67. 67. Eberhard Wolff - @ewolff Thank You!!

×