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
or Spring Cloud Components)

Outline

What are micro-services?

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

Lightweight Services and REST

job-trends

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.

Cloud Foundry

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)

Continuous Delivery

Book (Humble and Farley): http://continuousdelivery.com Netflix Blog: http://techblog.netflix.com/2013/08/deploying-netflix-api.html

Example Distributed System: Minified

customer-stores-blank

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.

Emergent features of micro-services systems

Coordination of distributed systems leads to boiler plate patterns

Spring IO Platform

spring-io-tree

Example: Coordination Boiler Plate

customer-stores-system

Bootification

How to bring the ease of Spring Boot to a micro-services architecture?

and many more... what to choose?

Netflix OSS

Mikey Cohen Netflix edge architecture, http://goo.gl/M159zi

Example: Spring Cloud and Netflix

customer-stores

Configuration Server

Spring Cloud Configuration Server

DEMO

Config Client

Consumers of config server can use client library as Spring Boot plugin

Features:

Environment Endpoint

Refresh Endpoint

RefreshScope

DEMO

@EnableConfigurationProperties(MyProps)
public class Application {

  @Autowired
  private MyProps props

  @RefreshScope
  @Bean
  public Service service() {
    new Service(props.name)
  }
}

Restart Endpoint

Encrypted Properties

DEMO

Discovery: Eureka

Eureka Client

@EnableEurekaClient
public class Application {
}

DEMO

Circuit Breaker: Hystrix

Hystrix Fallback

hystrix

Release It!: https://pragprog.com/book/mnee/release-it

Declarative Hystrix

DEMO

Hystrix Synchronous

private String getDefaultMessage() {
  return "Hello World Default";
}

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

Hystrix Future

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

//somewhere else
service.getMessageFuture().get();

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) {}
});

Circuit Breaker Metrics

DEMO

Metric Aggregation: Turbine

Ribbon

Feign

Feign cont.

DEMO

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);
}

Routing: Zuul

How Netflix uses Zuul

Spring Cloud Zuul Proxy

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

DEMO

Configuration: Archaius

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

Archaius: Spring Environment Bridge

Spring Cloud Bus

DEMO

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
#