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

Microservices with Netflix OSS & Spring Cloud - Arnaud Cogoluègnes

Feb 13, 2017

Download

Data & Analytics

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Microservices with Netflix OSS & Spring Cloud - Arnaud Cogoluègnes

Microservices withNetflix OSS & Spring Cloud

Arnaud CogoluègnesBerlin, September 19th, 2015

Page 2: Microservices with Netflix OSS & Spring Cloud - Arnaud Cogoluègnes

Speaker: Arnaud Cogoluègnes

Page 3: Microservices with Netflix OSS & Spring Cloud - Arnaud Cogoluègnes

Netflix OSS and Spring Cloud aren’t

limited to the cloudinfrastructure or container solutions

Page 4: Microservices with Netflix OSS & Spring Cloud - Arnaud Cogoluègnes

Netflix OSS and Spring Cloud are

application frameworksalso valid for traditional applications

open source

Page 5: Microservices with Netflix OSS & Spring Cloud - Arnaud Cogoluègnes

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 & Spring Cloud - Arnaud Cogoluègnes

The use case

Frontend

Backend(instance 1)

Backend(instance 2)

Service registry(Eureka)

Discovers

Registers

Registers

Balances

Page 7: Microservices with Netflix OSS & Spring Cloud - Arnaud Cogoluègnes

Netflix stack

Eureka (service registry)Hystrix (circuit breaker)

Ribbon (client load balancer)Zuul (proxy)

....

Page 8: Microservices with Netflix OSS & Spring Cloud - Arnaud Cogoluègnes

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 & Spring Cloud - Arnaud Cogoluègnes

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 & Spring Cloud - Arnaud Cogoluègnes

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 & Spring Cloud - Arnaud Cogoluègnes

Eureka server

Frontend

Backend(instance 1)

Backend(instance 2)

Service registry(Eureka)

Page 12: Microservices with Netflix OSS & Spring Cloud - Arnaud Cogoluègnes

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 & Spring Cloud - Arnaud Cogoluègnes

Eureka client

Frontend

Backend(instance 1)

Backend(instance 2)

Service registry(Eureka)

Discovers

Registers

Registers

Page 14: Microservices with Netflix OSS & Spring Cloud - Arnaud Cogoluègnes

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 & Spring Cloud - Arnaud Cogoluègnes

Client load balancer: Ribbon

Handles HTTP requestsBalances load and detects failures

Resolves services from Eureka

Page 16: Microservices with Netflix OSS & Spring Cloud - Arnaud Cogoluègnes

Client load balancing

Frontend

Backend(instance 1)

Backend(instance 2)

Service registry(Eureka)

Balances

Page 17: Microservices with Netflix OSS & Spring Cloud - Arnaud Cogoluègnes

Circuit breaker: Hystrix

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

Where? Around services calls

Page 18: Microservices with Netflix OSS & Spring Cloud - Arnaud Cogoluègnes

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 & Spring Cloud - Arnaud Cogoluègnes

Circuit breaker

Frontend

Backend(instance 1)

Backend(instance 2)

Service registry(Eureka)

Page 20: Microservices with Netflix OSS & Spring Cloud - Arnaud Cogoluègnes

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 & Spring Cloud - Arnaud Cogoluègnes

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

Page 22: Microservices with Netflix OSS & Spring Cloud - Arnaud Cogoluègnes

Summary

Mature, battle-tested librariesHelp to implement microservices architecture

Transparent for the developper

Page 23: Microservices with Netflix OSS & Spring Cloud - Arnaud Cogoluègnes

Questions?

Page 24: Microservices with Netflix OSS & Spring Cloud - Arnaud Cogoluègnes

Thank you!