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.

Java Microservices with Netflix OSS & Spring

2,418 views

Published on

Talk from Sydney JVM Community Meetup S04E01 : Microservice Frameworks
http://www.meetup.com/Sydney-JVM-Community/

Published in: Technology
  • DOWNLOAD FULL BOOKS, INTO AVAILABLE FORMAT ......................................................................................................................... ......................................................................................................................... 1.DOWNLOAD FULL. PDF EBOOK here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... 1.DOWNLOAD FULL. EPUB Ebook here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... 1.DOWNLOAD FULL. doc Ebook here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... 1.DOWNLOAD FULL. PDF EBOOK here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... 1.DOWNLOAD FULL. EPUB Ebook here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... 1.DOWNLOAD FULL. doc Ebook here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... ......................................................................................................................... ......................................................................................................................... .............. Browse by Genre Available eBooks ......................................................................................................................... Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult,
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here

Java Microservices with Netflix OSS & Spring

  1. 1. JAVA MICROSERVICES WITH NETFLIX OSS & SPRING CONOR SVENSSON
  2. 2. SPRING BOOT SPRING BOOT ▸ Stand-alone Spring-based applications ▸ Tomcat embedded container (supports Jetty & JBoss Undertow too) ▸ Starter POMs ▸ Annotation driven
  3. 3. SPRING BOOT DEPLOYMENT ▸ Self contained jar ▸ Web application archive ▸ Build targets ▸ $ mvn spring-boot:run ▸ $ gradle bootRun
  4. 4. SPRING BOOT
  5. 5. ACME HOME LOANS
  6. 6. ACME HOME LOANS LOAN APPLICATION EXTERNAL CREDIT SERVICE WEBSITE SERVICE SUBMISSION SERVICE 1 2 3
  7. 7. ACME HOME LOANS
  8. 8. ACME HOME LOANS
  9. 9. ACME HOME LOANS
  10. 10. SPRING BOOT TESTING ▸ spring-boot-starter-test starter POM provides: ▸ Spring Test ▸ Unit ▸ Hamcrest + Assert4J (v1.4) ▸ Mockito ▸ MockMvc ▸ @WebIntegrationTest
  11. 11. SPRING BOOT CONFIGURATION BEANS
  12. 12. SPRING CLOUD SPRING CLOUD ▸ Microservice friendly components ▸ Distributed & versioned configuration ▸ Service discovery ▸ Dynamic routing ▸ Circuit breakers ▸ Distributed messaging ▸ Getting started:
  13. 13. SPRING CLOUD SPRING CLOUD ▸ Config ▸ Netflix ▸ Bus ▸ Cloud Foundry ▸ Cluster ▸ Consul ▸ Security ▸ Sleuth ▸ Data Flow ▸ Stream ▸ Modules ▸ Task ▸ Zookeeper ▸ AWS ▸ Connectors ▸ CLI
  14. 14. SPRING CLOUD CONFIG SERVER ▸ Git hosted configuration repository ▸ SVN & filesystem also supported (see implementations of org.springframework.cloud.config.server.EnvironmentR epository) ▸ Multiple security options w/Spring Security (HTTP Basic -> OAuth bearer tokens) ▸ Push updates via Spring Cloud Bus
  15. 15. SPRING CLOUD CONFIG SERVER
  16. 16. SPRING CLOUD CONFIG SERVER CONFIGURATION application.yml:
  17. 17. SPRING CLOUD CLIENT CONFIGURATION FILE website.yml:
  18. 18. SPRING CLOUD RESOURCE FORMAT /{application}/{profile}[/{label}] /{application}-{profile}.yml /{label}/{application}-{profile}.yml /{application}-{profile}.properties /{label}/{application}-{profile}.properties (label: master by default)
  19. 19. SPRING CLOUD RESOLVED CONFIGURATION
  20. 20. SPRING CLOUD SHARED RESOURCES ▸ Place in application.yml in root of configuration repo ▸ Profile specific configuration always takes precedence over shared ▸ E.g. Eureka server (more on this shortly)
  21. 21. SPRING CLOUD CLIENT CONFIGURATION bootstrap.yml:
  22. 22. SPRING CLOUD CLIENT PROFILES ▸ Annotate classes to associate with a profile ▸ @Profile(“…”) ▸ Configuration (bootstrap/application properties) ▸ spring.profiles.active = … ▸ Command line ▸ -Dspring.profiles.active=… ▸ Environment variable ▸ SPRING_PROFILES_ACTIVE=…
  23. 23. SPRING CLOUD RESOLVED CLIENT CONFIGURATION
  24. 24. SPRING CLOUD CONFIG SERVER GOTCHAS ▸ Client’s don’t fail on Config Server failure - boot with defaults (e.g. port 8080) ▸ To enable use spring.cloud.config.failFast=true ▸ Enable retries: ▸ Add spring-retry and spring-boot-starter-aop ▸ spring.cloud.config.retry.
  25. 25. NETFLIX OSS + SPRING SPRING CLOUD NETFLIX ▸ Service discovery (Eureka) ▸ Client side load balancing (Ribbon) ▸ Dynamic routing (Zuul) ▸ Circuit breaker (Hystrix) ▸ + a few others…
  26. 26. NETFLIX OSS + SPRING EUREKA ▸ Service discovery client & server ▸ Maintains registry of clients with metadata ▸ Host/port ▸ Health indicator URL ▸ Client heartbeats (30 sec default - changing not encouraged) ▸ Lease renewed with server ▸ Service available when client & server(s) metadata cache all in sync ▸ Can take up to 3 heart beats
  27. 27. NETFLIX OSS + SPRING EUREKA SERVER
  28. 28. NETFLIX OSS + SPRING EUREKA SERVER DASHBOARD
  29. 29. NETFLIX OSS + SPRING EUREKA CLIENT SETUP @EnableEurekaClient annotation application.yml in Config Server repo
  30. 30. NETFLIX OSS + SPRING RIBBON ▸ Client side loan balancer ▸ Can delegate to Eureka for server lists ▸ Or list servers ▸ stores.ribbon.listOfServers=… + ribbon.eureka.enabled=false
  31. 31. NETFLIX OSS + SPRING RIBBON USAGE ▸ Via RestTemplate ▸ No different to normal usage - Spring Cloud Commons abstraction ▸ Qualifier’s required if using regular & Ribbon enabled RestTemplate
  32. 32. NETFLIX OSS + SPRING ZUUL ▸ JVM based router & load balancer ▸ Provides single point of entry to services ▸ Including single point of authentication ▸ By default creates route for every service in Eureka ▸ Refer to http://localhost/credit-service routes to http://credit- service ▸ Filters provide limited entry points to system
  33. 33. NETFLIX OSS + SPRING ZUUL SERVER CREATION ‣ Include dependency spring-cloud-starter-zuul ‣ @EnableZuulProxy application annotation ‣ E.g. Allow access only to credit-service
  34. 34. NETFLIX OSS + SPRING SIDECAR ▸ Non-JVM access to components via Zuul proxy ▸ Setup Spring Boot application with @EnableSidecar ▸ Configure for your service: ▸ sidecar.port=… + sidecar.health-ui=… ▸ Access all services by Zuul URL (Sidecar running on port 80) ▸ http://localhost/config-server
  35. 35. NETFLIX OSS + SPRING HYSTRIX ▸ Circuit breaker ▸ Threshold breached (20 failures in 5 seconds) => breaker kicks in ▸ Default timeout threshold 1 second ▸ Per dependency thread pools ▸ Async command support (not Spring @Async) ▸ Sync or async fallback
  36. 36. NETFLIX OSS + SPRING HYSTRIX CLIENT ▸ @EnableCircuitBreaker application annotation ▸ @HystrixCommand on applicable methods
  37. 37. NETFLIX OSS + SPRING
  38. 38. NETFLIX OSS + SPRING HYSTRIX STREAM - PRE-REQUESTS
  39. 39. NETFLIX OSS + SPRING HYSTRIX STREAM - POST-REQUESTS
  40. 40. NETFLIX OSS + SPRING HYSTRIX DASHBOARD
  41. 41. NETFLIX OSS + SPRING HYSTRIX STREAM
  42. 42. NETFLIX OSS + SPRING HYSTRIX DASHBOARD
  43. 43. NETFLIX OSS + SPRING TURBINE - AGGREGATE MULTIPLE HYSTRIX CLIENTS
  44. 44. NETFLIX OSS + SPRING MONITORING ▸ Add dependency spring-boot-actuator ▸ Makes available various application metrics via /metrics endpoint ▸ Integration also available with DropWizard metrics (add dependency) ▸ Spring Cloud ▸ Spectator (supersedes Servo) - metrics collection ▸ Atlas - metrics backend
  45. 45. NETFLIX OSS + SPRING
  46. 46. NETFLIX OSS + SPRING LOGGING ▸ Logback is the default choice ▸ Alternative starters are provided ▸ Using alternatives (such as log4j2) requires exclusions throughout the starter POMs
  47. 47. NETFLIX OSS + SPRING DOWNSIDES ▸ A lot of magic - e.g. CORS filters ▸ ADD (Annotation driven development) ▸ Dependency management ▸ RestTemplates - Ribbon enabled != Standard HTTP ▸ Lack of proper polygot support - libraries are in Java (Sidecar is OK as a middle ground) ▸ Spring Hystrix documentation is pretty light
  48. 48. NETFLIX OSS + SPRING ALTHOUGH…
  49. 49. NETFLIX OSS + SPRING RESOURCES ▸ Spring Cloud documentation - http://projects.spring.io/spring-cloud/spring-cloud.html ▸ Spring Boot sample projects - https://github.com/spring-projects/spring-boot/tree/ master/spring-boot-samples ▸ Spring Cloud sample projects - https://github.com/spring-cloud-samples ▸ Hystrix annotations - https://github.com/Netflix/Hystrix/tree/master/hystrix-contrib/ hystrix-javanica ▸ Useful demonstration of Spring Cloud usage - http://callistaenterprise.se/blogg/teknik/ 2015/05/20/blog-series-building-microservices/ ▸ Spring project dependency selector - http://start.spring.io/ ▸ Code to accompany this talk - https://github.com/conor10/homeloans ▸ https://www.huffle.com.au
  50. 50. NETFLIX OSS + SPRING THANKS conor@huffle.com.au

×