Spring Cloud, Spring Boot and Netflix OSS - - PowerPoint PPT Presentation

spring cloud spring boot and netflix oss
SMART_READER_LITE
LIVE PREVIEW

Spring Cloud, Spring Boot and Netflix OSS - - PowerPoint PPT Presentation

Spring Cloud, Spring Boot and Netflix OSS http://localhost:4000/decks/cloud-boot-netflix.html Spencer Gibb twitter: @spencerbgibb email: sgibb@pivotal.io Dave Syer twitter: @david_syer email: dsyer@pivotal.io ( Spring Boot and Netflix OSS or


slide-1
SLIDE 1

Spring Cloud, Spring Boot and Netflix OSS

Spencer Gibb twitter: @spencerbgibb email: sgibb@pivotal.io Dave Syer twitter: @david_syer email: dsyer@pivotal.io (Spring Boot and Netflix OSS

  • r Spring Cloud Components)

http://localhost:4000/decks/cloud-boot-netflix.html 1 of 44 10/09/14 18:50

slide-2
SLIDE 2

Outline

Define microservices Outline some distributed system problems Introduce Netflix OSS and its integration with Spring Boot Spring Cloud demos

http://localhost:4000/decks/cloud-boot-netflix.html 2 of 44 10/09/14 18:50

slide-3
SLIDE 3

What are micro-services?

Not monolithic :-) Smaller units of a larger system Runs in its own process Lightweight communication protocols Single Responsibility Principle The UNIX way http://www.slideshare.net/ewolff/micro-services-small-is-beautiful http://martinfowler.com/articles/microservices.html http://davidmorgantini.blogspot.com/2013/08/micro-services-what-are- micro-services.html

http://localhost:4000/decks/cloud-boot-netflix.html 3 of 44 10/09/14 18:50

slide-4
SLIDE 4

Lightweight Services and REST

There is a strong trend in distributed systems with lightweight architectures People have started to call them "microservices"

http://localhost:4000/decks/cloud-boot-netflix.html 4 of 44 10/09/14 18:50

slide-5
SLIDE 5

Spring Boot

It needs to be super easy to implement and update a service:

@RestController class ThisWillActuallyRun { @RequestMapping("/") String home() { Hello World! } }

and you don't get much more "micro" than that.

http://localhost:4000/decks/cloud-boot-netflix.html 5 of 44 10/09/14 18:50

slide-6
SLIDE 6

Cloudfoundry

Deploying services needs to be simple and reproducible

$ cf push app.groovy

and you don't get much more convenient than that. (Same argument for other PaaS solutions)

http://localhost:4000/decks/cloud-boot-netflix.html 6 of 44 10/09/14 18:50

slide-7
SLIDE 7

Continuous Delivery

Microservices lend themselves to continuous delivery. You need continuous delivery Book (Humble and Farley): http://continuousdelivery.com Netflix Blog: http://techblog.netflix.com/2013/08/deploying-netflix-api.html

http://localhost:4000/decks/cloud-boot-netflix.html 7 of 44 10/09/14 18:50

slide-8
SLIDE 8

Example Distributed System: Minified

http://localhost:4000/decks/cloud-boot-netflix.html 8 of 44 10/09/14 18:50

slide-9
SLIDE 9

http://localhost:4000/decks/cloud-boot-netflix.html 9 of 44 10/09/14 18:50

slide-10
SLIDE 10

No Man (Microservice) is an Island

It's excellent to be able to implement a microservice really easily (Spring Boot), but building a system that way surfaces "non-functional" requirements that you otherwise didn't have.

There are laws of physics that make some problems unsolvable (consistency, latency), but brittleness and manageability can be addressed with generic, boiler plate patterns.

http://localhost:4000/decks/cloud-boot-netflix.html 10 of 44 10/09/14 18:50

slide-11
SLIDE 11

Emergent features of micro- services systems

Coordination of distributed systems leads to boiler plate patterns Distributed/versioned configuration Service registration and discovery Routing Service-to-service calls Load balancing Circuit Breaker Asynchronous Distributed messaging

http://localhost:4000/decks/cloud-boot-netflix.html 11 of 44 10/09/14 18:50

slide-12
SLIDE 12

Example: Coordination Boiler Plate

http://localhost:4000/decks/cloud-boot-netflix.html 12 of 44 10/09/14 18:50

slide-13
SLIDE 13

Bootification

How to bring the ease of Spring Boot to a micro-services architecture? Netflix OSS Consul etcd zookeeper custom doozerd ha proxy nginx Typesafe Config and many more... what to choose?

http://localhost:4000/decks/cloud-boot-netflix.html 13 of 44 10/09/14 18:50

slide-14
SLIDE 14

Netflix OSS

Eureka Hystrix & Turbine Ribbon Feign Zuul Archaius Curator Asgaard ... Mikey Cohen Netflix edge architecture, http://goo.gl/M159zi

http://localhost:4000/decks/cloud-boot-netflix.html 14 of 44 10/09/14 18:50

slide-15
SLIDE 15

Example: Spring Cloud and Netflix

http://localhost:4000/decks/cloud-boot-netflix.html 15 of 44 10/09/14 18:50

slide-16
SLIDE 16

Configuration Server

Pluggable source Git implementation Versioned Rollback-able Configuration client auto-configured via starter

http://localhost:4000/decks/cloud-boot-netflix.html 16 of 44 10/09/14 18:50

slide-17
SLIDE 17

Spring Cloud Configuration Server

Supports applications <appname>.properties Supports environments <appname>-<envname>.yml Default environment application.properties applies to all applications and environments DEMO

http://localhost:4000/decks/cloud-boot-netflix.html 17 of 44 10/09/14 18:50

slide-18
SLIDE 18

Config Client

Consumers of config server can use client library as Spring Boot plugin Features: Bootstrap Environment from server POST to /env to change Environment @RefreshScope for atomic changes to beans via Spring lifecycle POST to /refresh POST to /restart

http://localhost:4000/decks/cloud-boot-netflix.html 18 of 44 10/09/14 18:50

slide-19
SLIDE 19

Environment Endpoint

POST to /env Re-binds @ConfigurationProperties Resets loggers if any logging.level changes are detected Sends EnvironmentChangeEvent with list of properties that changed

http://localhost:4000/decks/cloud-boot-netflix.html 19 of 44 10/09/14 18:50

slide-20
SLIDE 20

Refresh Endpoint

POST to /refresh Re-loads configuration including remote config server Re-binds @ConfigurationProperties Resets @RefreshScope cache

http://localhost:4000/decks/cloud-boot-netflix.html 20 of 44 10/09/14 18:50

slide-21
SLIDE 21

RefreshScope

Annotate @Beans Atomic updates during /refresh DEMO

@EnableConfigurationProperties(MyProps) public class Application { @Autowired private MyProps props @RefreshScope @Bean public Service service() { new Service(props.name) } }

http://localhost:4000/decks/cloud-boot-netflix.html 21 of 44 10/09/14 18:50

slide-22
SLIDE 22

Restart Endpoint

POST to /restart closes application context and refreshes it Probably more useful in development than production (leaks?) Disabled by default

http://localhost:4000/decks/cloud-boot-netflix.html 22 of 44 10/09/14 18:50

slide-23
SLIDE 23

Encrypted Properties

Authenticated clients have access to unencrypted data. Only encrypted data is stored in git. Support for server side or client side decryption DEMO

http://localhost:4000/decks/cloud-boot-netflix.html 23 of 44 10/09/14 18:50

slide-24
SLIDE 24

Discovery: Eureka

Service Registration Server Highly Available In AWS terms, multi Availability Zone and Region aware

http://localhost:4000/decks/cloud-boot-netflix.html 24 of 44 10/09/14 18:50

slide-25
SLIDE 25

Eureka Client

Register service instances with Eureka Server @EnableEurekaClient auto registers instance in server Eureka Server Eureka Client

@EnableEurekaClient public class Application { }

DEMO

http://localhost:4000/decks/cloud-boot-netflix.html 25 of 44 10/09/14 18:50

slide-26
SLIDE 26

Circuit Breaker: Hystrix

latency and fault tolerance isolates access to other services stops cascading failures enables resilience circuit breaker pattern dashboard Release It!: https://pragprog.com/book/mnee/release-it

http://localhost:4000/decks/cloud-boot-netflix.html 26 of 44 10/09/14 18:50

slide-27
SLIDE 27

Declarative Hystrix

Programmatic access is cumbersome @HystrixCommand to the rescue @EnableHystrix via starter pom Wires up spring aop aspect DEMO

http://localhost:4000/decks/cloud-boot-netflix.html 27 of 44 10/09/14 18:50

slide-28
SLIDE 28

Hystrix Synchronous

private String getDefaultMessage() { return "Hello World Default"; } @HystrixCommand(fallbackMethod="getDefaultMessage") public String getMessage() { return restTemplate.getForObject(/*...*/); }

http://localhost:4000/decks/cloud-boot-netflix.html 28 of 44 10/09/14 18:50

slide-29
SLIDE 29

Hystrix Future

@HystrixCommand(fallbackMethod="getDefaultMessage") public Future<String> getMessageFuture() { return new AsyncResult<String>() { public String invoke() { return restTemplate.getForObject(/*...*/); } }; } //somewhere else service.getMessageFuture().get();

http://localhost:4000/decks/cloud-boot-netflix.html 29 of 44 10/09/14 18:50

slide-30
SLIDE 30

Hystrix Observable

@HystrixCommand(fallbackMethod="getDefaultMessage") public Observable<String> getMessageRx() { return new ObservableResult<String>() { public String invoke() { return restTemplate.getForObject(/*...*/); } }; } //somewhere else helloService.getMessageRx().subscribe(new Observer<String>() { @Override public void onCompleted() {} @Override public void onError(Throwable e) {} @Override public void onNext(String s) {} });

http://localhost:4000/decks/cloud-boot-netflix.html 30 of 44 10/09/14 18:50

slide-31
SLIDE 31

Circuit Breaker Metrics

Via actuator /metrics Server side event stream /hystrix.stream Dashboard app via @EnableHystrixDashboard More coming... DEMO

http://localhost:4000/decks/cloud-boot-netflix.html 31 of 44 10/09/14 18:50

slide-32
SLIDE 32

Metric Aggregation: Turbine

Aggregator for Hystrix data Pluggable locator Static list Eureka

http://localhost:4000/decks/cloud-boot-netflix.html 32 of 44 10/09/14 18:50

slide-33
SLIDE 33

Ribbon

Client side load balancer Pluggable transport Protocols: http, tcp, udp Pluggable load balancing algorithms Round robin, “best available”, random, response time based Pluggable source for server list Static list, Eureka!

http://localhost:4000/decks/cloud-boot-netflix.html 33 of 44 10/09/14 18:50

slide-34
SLIDE 34

Feign

Declarative web service client definition Annotate an interface Highly customizable Encoders/decoders Annotation processors (Feign, JAX-RS) Logging Supports Ribbon and therefore Eureka

http://localhost:4000/decks/cloud-boot-netflix.html 34 of 44 10/09/14 18:50

slide-35
SLIDE 35

Feign cont.

Auto-configuration Support for Spring MVC annotations Uses Spring MessageConverter’s for decoder/encoder DEMO

http://localhost:4000/decks/cloud-boot-netflix.html 35 of 44 10/09/14 18:50

slide-36
SLIDE 36

Feign cont.

public interface HelloClient { @RequestMapping(method = RequestMethod.GET, value = "/hello") Message hello(); @RequestMapping(method = RequestMethod.POST, value = "/hello", consumes = "application/json") Message hello(Message message); }

http://localhost:4000/decks/cloud-boot-netflix.html 36 of 44 10/09/14 18:50

slide-37
SLIDE 37

Routing: Zuul

JVM based router and filter Similar routing role as httpd, nginx, or CF go router Fully programmable rules and filters Groovy Java any JVM language

http://localhost:4000/decks/cloud-boot-netflix.html 37 of 44 10/09/14 18:50

slide-38
SLIDE 38

How Netflix uses Zuul

Authentication Insights Stress Testing Canary Testing Dynamic Routing Service Migration Load Shedding Security Static Response handling Active/Active traffic management

http://localhost:4000/decks/cloud-boot-netflix.html 38 of 44 10/09/14 18:50

slide-39
SLIDE 39

Spring Cloud Zuul Proxy

Store routing rules in config server zuul.proxy.route.customers: /customers uses Hystrix->Ribbon->Eureka to forward requests to appropriate service

@EnableZuulProxy @Controller class Application { @RequestMapping("/") String home() { return 'redirect:/index.html#/customers' } }

DEMO

http://localhost:4000/decks/cloud-boot-netflix.html 39 of 44 10/09/14 18:50

slide-40
SLIDE 40

Configuration: Archaius

Client side configuration library extends apache commons config extendible sources Polling or push updates

DynamicStringProperty myprop = DynamicPropertyFactory.getInstance() .getStringProperty("my.prop"); someMethod(myprop.get());

http://localhost:4000/decks/cloud-boot-netflix.html 40 of 44 10/09/14 18:50

slide-41
SLIDE 41

Archaius: Spring Environment Bridge

Auto-configured Allows Archaius Dynamic*Properties to find values via Spring Environment Existing Netflix libraries configured via application. {properties,yml} and/or Spring Cloud Config Server

http://localhost:4000/decks/cloud-boot-netflix.html 41 of 44 10/09/14 18:50

slide-42
SLIDE 42

Spring Cloud Bus

Lightweight messaging bus using spring integration abstractions

spring-amqp, rabbitmq and http

  • ther implementations possible

Send messages to all services or... To just one applications nodes (ie just service x) ?destination=x Post to /bus/env sends environment updates Post to /bus/refresh sends a refresh command DEMO

http://localhost:4000/decks/cloud-boot-netflix.html 42 of 44 10/09/14 18:50

slide-43
SLIDE 43

Spring Cloud Starters

spring-cloud-starter spring-cloud-starter-hystrix spring-cloud-starter-bus-amqp spring-cloud-starter-hystrix- dashboard spring-cloud-starter- cloudfoundry spring-cloud-starter-turbine spring-cloud-starter-eureka spring-cloud-starter-zuul spring-cloud-starter-eureka- server

http://localhost:4000/decks/cloud-boot-netflix.html 43 of 44 10/09/14 18:50

slide-44
SLIDE 44

Links

http://github.com/spring-cloud http://github.com/spring-cloud-samples http://blog.spring.io http://presos.dsyer.com/decks/cloud-boot-netflix.html Twitter: @spencerbgibb, @david_syer Email: sgibb@pivotal.io, dsyer@pivotal.io

http://localhost:4000/decks/cloud-boot-netflix.html 44 of 44 10/09/14 18:50