Microservices with Netflix OSS and Spring Cloud

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

Transcript of Microservices with Netflix OSS and Spring Cloud

Page 1: Microservices with Netflix OSS and Spring Cloud

Microservices withNetflix OSS & Spring Cloud

Arnaud CogoluègnesBerlin, September 19th, 2015

Page 2: Microservices with Netflix OSS and Spring Cloud

Speaker: Arnaud Cogoluègnes

Page 3: Microservices with Netflix OSS and Spring Cloud

Netflix OSS and Spring Cloud aren’t

limited to the cloudinfrastructure or container solutions

Page 4: Microservices with Netflix OSS and Spring Cloud

Netflix OSS and Spring Cloud are

application frameworksalso valid for traditional applications

open source

Page 5: Microservices with Netflix OSS and Spring Cloud

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)

Page 6: Microservices with Netflix OSS and Spring Cloud

The use case

Frontend

Backend(instance 1)

Backend(instance 2)

Service registry(Eureka)

Discovers

Registers

Registers

Balances

Page 7: Microservices with Netflix OSS and Spring Cloud

Netflix stack

Eureka (service registry)Hystrix (circuit breaker)

Ribbon (client load balancer)Zuul (proxy)

....

Page 8: Microservices with Netflix OSS and Spring Cloud

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

Page 9: Microservices with Netflix OSS and Spring Cloud

Spring Boot

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

All the Spring stuff:Dependency injection, transaction

management, REST, ...

Page 10: Microservices with Netflix OSS and Spring Cloud

Eureka server with Spring Boot

@SpringBootApplication

@EnableEurekaServer // activates Eureka

public class EurekaServer {

public static void main(String[] args) {

SpringApplication.run(EurekaServer.class, args);

}

}

Page 11: Microservices with Netflix OSS and Spring Cloud

Eureka server

Frontend

Backend(instance 1)

Backend(instance 2)

Service registry(Eureka)

Page 12: Microservices with Netflix OSS and Spring Cloud

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

}

}

Page 13: Microservices with Netflix OSS and Spring Cloud

Eureka client

Frontend

Backend(instance 1)

Backend(instance 2)

Service registry(Eureka)

Discovers

Registers

Registers

Page 14: Microservices with Netflix OSS and Spring Cloud

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;

}

Page 15: Microservices with Netflix OSS and Spring Cloud

Client load balancer: Ribbon

Handles HTTP requestsBalances load and detects failures

Resolves services from Eureka

Page 16: Microservices with Netflix OSS and Spring Cloud

Client load balancing

Frontend

Backend(instance 1)

Backend(instance 2)

Service registry(Eureka)

Balances

Page 17: Microservices with Netflix OSS and Spring Cloud

Circuit breaker: Hystrix

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

Where? Around services calls

Page 18: Microservices with Netflix OSS and Spring Cloud

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

}

}

Page 19: Microservices with Netflix OSS and Spring Cloud

Circuit breaker

Frontend

Backend(instance 1)

Backend(instance 2)

Service registry(Eureka)

Page 20: Microservices with Netflix OSS and Spring Cloud

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

}

}

Page 21: Microservices with Netflix OSS and Spring Cloud

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

Page 22: Microservices with Netflix OSS and Spring Cloud

Summary

Mature, battle-tested librariesHelp to implement microservices architecture

Transparent for the developper

Page 23: Microservices with Netflix OSS and Spring Cloud

Questions?

Page 24: Microservices with Netflix OSS and Spring Cloud

Thank you!