microservices with netflix oss & spring cloud - arnaud cogoluègnes

24
Microservices with Netflix OSS & Spring Cloud Arnaud Cogoluègnes Berlin, September 19th, 2015

Upload: distributed-matters

Post on 13-Feb-2017

776 views

Category:

Data & Analytics


2 download

TRANSCRIPT

Microservices withNetflix OSS & Spring Cloud

Arnaud CogoluègnesBerlin, September 19th, 2015

Speaker: Arnaud Cogoluègnes

Netflix OSS and Spring Cloud aren’t

limited to the cloudinfrastructure or container solutions

Netflix OSS and Spring Cloud are

application frameworksalso valid for traditional applications

open source

Docker Container Docker Container

Where does it fit?

Spring Boot Application(Netflix OSS & Spring Cloud)

Java Virtual Machine

Eureka Service Registry

Java Virtual Machine

Infrastructure(Mesos, vanilla datacenter, VM, Cloud Foundry, AWS, laptop)

The use case

Frontend

Backend(instance 1)

Backend(instance 2)

Service registry(Eureka)

Discovers

Registers

Registers

Balances

Netflix stack

Eureka (service registry)Hystrix (circuit breaker)

Ribbon (client load balancer)Zuul (proxy)

....

Spring Cloud

Built on top of Spring BootSpring-ifies some nifty libraries (e.g. Netflix)Provides goodies (e.g. configuration server)Pretty much all you need for microservices

Spring Boot

Spring Framework for the massesNo XML, no container (as you wish)

All the Spring stuff:Dependency injection, transaction

management, REST, ...

Eureka server with Spring Boot

@SpringBootApplication

@EnableEurekaServer // activates Eureka

public class EurekaServer {

public static void main(String[] args) {

SpringApplication.run(EurekaServer.class, args);

}

}

Eureka server

Frontend

Backend(instance 1)

Backend(instance 2)

Service registry(Eureka)

Eureka client with Spring Cloud

@SpringBootApplication

@EnableEurekaClient // application registers to Eureka

public class BackendServiceApplication {

public static void main(String[] args) {

SpringApplication.run(BackendServiceApplication.class, args);

}

}

Eureka client

Frontend

Backend(instance 1)

Backend(instance 2)

Service registry(Eureka)

Discovers

Registers

Registers

REST client call

@Repository

public class ContactRepository {

@Autowired RestTemplate restClient;

public ContactsResponse contacts() {

ContactsResponse response = restClient.getForObject(

"http://backend-service/contacts", // host = service name

ContactsResponse. class

);

response.setOk( true);

return response;

}

Client load balancer: Ribbon

Handles HTTP requestsBalances load and detects failures

Resolves services from Eureka

Client load balancing

Frontend

Backend(instance 1)

Backend(instance 2)

Service registry(Eureka)

Balances

Circuit breaker: Hystrix

Why? To prevent cascading failureHow? async, detect failures, open/close

Where? Around services calls

Hystrix with Spring Cloud

@Repository

public class ContactRepository {

@HystrixCommand(fallbackMethod = "contactsFailure")

public ContactsResponse contacts() {

// real call (protected by circuit breaker)

}

public ContactsResponse contactsFailure() {

// fallback, when real call fails

}

}

Circuit breaker

Frontend

Backend(instance 1)

Backend(instance 2)

Service registry(Eureka)

Hystrix activation

@SpringBootApplication

@EnableCircuitBreaker // protects targeted methods

@EnableEurekaClient

@EnableHystrixDashboard // enables dashboard

public class FrontApplication {

public static void main(String[] args) {

SpringApplication.run(FrontApplication.class,args);

}

}

Source: https://github.com/Netflix/Hystrix

Summary

Mature, battle-tested librariesHelp to implement microservices architecture

Transparent for the developper

Questions?

Thank you!