In this talk we are going to discuss some of the key components of Spring Cloud. This includes the Netflix OSS integrations for Spring Boot apps which include Service Discovery (Eureka), Circuit Breaker (Hystrix), Intelligent Routing (Zuul) and Client Side Load Balancing (Ribbon). We will also touch on the Spring Cloud centralised configuration server and deploy these apps to Cloud Foundry.
17. SPRING CLOUD
SPRING CLOUD
▸ Microservice friendly components
▸ Distributed & versioned configuration
▸ Service discovery
▸ Dynamic routing
▸ Circuit breakers
▸ Distributed messaging
▸ Getting started:
18. SPRING CLOUD
SPRING CLOUD
▸ Config
▸ Netflix
▸ Bus
▸ Cloud Foundry
▸ Cluster
▸ Consul
▸ Security
▸ Sleuth
▸ Data Flow
▸ Stream
▸ Modules
▸ Task
▸ Zookeeper
▸ AWS
▸ Connectors
▸ CLI
19. 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
25. 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)
29. 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.
30.
31. NETFLIX OSS + SPRING
SPRING CLOUD NETFLIX
▸ Service discovery (Eureka)
▸ Client side load balancing (Ribbon)
▸ Dynamic routing (Zuul)
▸ Circuit breaker (Hystrix)
▸ + a few others…
32. 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
35. NETFLIX OSS + SPRING
EUREKA CLIENT SETUP
@EnableEurekaClient annotation
application.yml in Config Server repo
36. 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
37. 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
38. 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
39. NETFLIX OSS + SPRING
ZUUL SERVER CREATION
‣ Include dependency spring-cloud-starter-zuul
‣ @EnableZuulProxy application annotation
‣ E.g. Allow access only to credit-service
40. 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
41. 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
42. NETFLIX OSS + SPRING
HYSTRIX CLIENT
▸ @EnableCircuitBreaker application annotation
▸ @HystrixCommand on applicable methods
50. 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
53. CLOUD FOUNDRY
CLOUD FOUNDRY
▸ Cloud Foundry
▸ PAAS
▸ Supports multiple languages & frameworks
▸ Manages VM containers for deployments within a
“space”
▸ Multiple spaces for different environments
▸ Command-line tool (cf)
54. CLOUD FOUNDRY
SPRING CLOUD FOUNDRY + CONNECTORS
▸ Spring Cloud Foundry
▸ Binding of CF single sign on to your services
▸ Integration with CF Service Discovery
▸ Spring Cloud Connectors
▸ Connectors for Spring Cloud on CF
▸ Config Server
▸ Eureka (Service Discovery)
▸ Hystrix (Circuit Breaker)
58. NETFLIX OSS + SPRING
DOWNSIDES
▸ A lot of magic
▸ 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
▸ £££ to use core components (Config Server, Eureka) on Cloud Foundry