More Related Content Similar to Microservices with Spring and Cloud Foundry (20) Microservices with Spring and Cloud Foundry33. © mimacom 30.03.2015
Summary
• Service discovery: Netflix Eureka
• Client-side load balancing: Netflix Ribbon
• Circuit breaker: Netflix Hystrix
• API gateway: Netflix Zuul
34. © mimacom 30.03.2015
Summary
• Service discovery: Netflix Eureka
• Client-side load balancing: Netflix Ribbon
• Circuit breaker: Netflix Hystrix
• API gateway: Netflix Zuul
• Configuration: Spring Cloud Config
• Spring Cloud Bus for refreshing the config
35. © mimacom 30.03.2015
Spring IO
CLOUD
SERVICE REGISTRY,
CIRCUIT BREAKER, METRICS
CORE
FRAMEWORK SECURITY GROOVY REACTOR
IOEXECUTIONIOFOUNDATION
GRAILS
FULL STACK, WEB
XD
STREAMS, TAPS, JOBS
BOOT
BOOTABLE, MINIMAL, OPS-READY
BATCH
JOBS, STEPS,
READERS, WRITERS
DATA
RELATIONAL DATA NON-RELATIONAL DATA
BIG DATA
INGESTION, EXPORT,
ORCHESTRATION, HADOOP
WEB
CONTROLLERS, REST,
WEBSOCKET
INTEGRATION
CHANNELS, FILTERS,
ADAPTERS, TRANSFORMERS
IOCOORDINATION
38. © mimacom 30.03.2015
Spring Boot: Short Introduction
• Create standalone Spring applications
• Provide opinionated “starter” POMs to simplify
your maven configuration
• Automatically configure Spring whenever
possible
• Provide production-ready features such as metrics,
health checks and externalized configuration
“Takes an opinionated view of building
production-ready Spring applications”
40. © mimacom 30.03.2015
Spring Boot: Key Features
MyApplication.java:
@SpringBootApplication
public class EurekaServer {
public static void main(String[] args) {
SpringApplication.run(MyApplication.class, args);
}
}
41. © mimacom 30.03.2015
Spring Boot: Key Features
MyApplication.java:
@SpringBootApplication
public class EurekaServer {
public static void main(String[] args) {
SpringApplication.run(MyApplication.class, args);
}
}
pom.xml:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
42. © mimacom 30.03.2015
Spring Boot: Key Features
MyApplication.java:
@SpringBootApplication
public class EurekaServer {
public static void main(String[] args) {
SpringApplication.run(MyApplication.class, args);
}
}
pom.xml:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
Configuration file: application.yml, bootstrap.yml
46. © mimacom 30.03.2015
Spring Cloud Config: Server
Spring Cloud
Config Server
GIT
SVN
File
ConfigServer.java:
@SpringBootApplication
@EnableConfigServer
public class ConfigServer {…}
47. © mimacom 30.03.2015
Spring Cloud Config: Server
Spring Cloud
Config Server
GIT
SVN
File
ConfigServer.java:
@SpringBootApplication
@EnableConfigServer
public class ConfigServer {…}
application.yml
spring.cloud.config.git.uri: https://github.com/…
48. © mimacom 30.03.2015
Spring Cloud Config: Client
Spring Cloud
Config Server
Application
Spring Cloud
Config Client
Application
Spring Cloud
Config Client
Application
Spring Cloud
Config Client
49. © mimacom 30.03.2015
Spring Cloud Config: Client
Spring Cloud
Config Server
Application
Spring Cloud
Config Client
Application
Spring Cloud
Config Client
Application
Spring Cloud
Config Client
bootstrap.yml:
spring.cloud.config.uri: ${vcap.services.configserver.credentials.uri}
51. © mimacom 30.03.2015
Spring Cloud Netflix: Eureka
Spring Cloud
Eureka Server
Application
Spring Cloud
Eureka Client
Application
Spring Cloud
Eureka Client
Application
Spring Cloud
Eureka Client
52. © mimacom 30.03.2015
Spring Cloud Netflix: Eureka
Spring Cloud
Eureka Server
Application
Spring Cloud
Eureka Client
Application
Spring Cloud
Eureka Client
Application
Spring Cloud
Eureka Client
EurekaServer.java:
@SpringBootApplication
@EnableEurekaServer
public class EurekaServer {…}
53. © mimacom 30.03.2015
Spring Cloud Netflix: Eureka
Spring Cloud
Eureka Server
Application
Spring Cloud
Eureka Client
Application
Spring Cloud
Eureka Client
Application
Spring Cloud
Eureka Client
EurekaServer.java:
@SpringBootApplication
@EnableEurekaServer
public class EurekaServer {…}
Application.java:
@SpringBootApplication
@EnableEurekaClient
public class Application {…}
55. © mimacom 30.03.2015
Spring Cloud Netflix: Ribbon
RibbonSample.java:
public class RibbonSample {
@Autowired
private RestTemplate restTemplate;
public void foo() {
restTemplate.postForLocation(“http://customers/add”, customer);
}
}
57. © mimacom 30.03.2015
Spring Cloud Netflix: Zuul
ApiGateway.java:
@SpringBootApplication
@EnableZuulProxy
public class ApiGateway {…}
58. © mimacom 30.03.2015
Spring Cloud Netflix: Zuul
ApiGateway.java:
@SpringBootApplication
@EnableZuulProxy
public class ApiGateway {…}
application.yml:
zuul:
ignoredServices: *
routes:
users: /myusers/**
60. © mimacom 30.03.2015
Spring Cloud Netflix: Hystrix
PentagonApplication.java:
@SpringBootApplication
@EnableHystrix
public class PentagonApplication {…}
61. © mimacom 30.03.2015
Spring Cloud Netflix: Hystrix
PentagonApplication.java:
@SpringBootApplication
@EnableHystrix
public class PentagonApplication {…}
Store.java:
@HystrixCommand(fallbackMethod = "defaultStores")
public Object getStores(Map<String, Object> parameters) {
//Call another service over HTTP (ribbon)
}
public Object defaultStores(Map<String, Object> parameters) {
return /* some fallback data */;
}
62. © mimacom 30.03.2015
Spring Cloud Netflix: Hystrix
PentagonApplication.java:
@SpringBootApplication
@EnableHystrix
public class PentagonApplication {…}
Store.java:
@HystrixCommand(fallbackMethod = "defaultStores")
public Object getStores(Map<String, Object> parameters) {
//Call another service over HTTP (ribbon)
}
public Object defaultStores(Map<String, Object> parameters) {
return /* some fallback data */;
}
63. © mimacom 30.03.2015
Spring Cloud Netflix: Hystrix
PentagonApplication.java:
@SpringBootApplication
@EnableHystrix
public class PentagonApplication {…}
Store.java:
@HystrixCommand(fallbackMethod = "defaultStores")
public Object getStores(Map<String, Object> parameters) {
//Call another service over HTTP (ribbon)
}
public Object defaultStores(Map<String, Object> parameters) {
return /* some fallback data */;
}
67. © mimacom 30.03.2015
Demo Application
Zuul Server
Service
Discovery
Eureka
Customers Stores
Config
Server
Hystrix
Dashboard
Browser
Turbine
72. © mimacom 30.03.2015
Summary
• Netflix Eureka: Service registry & discovery
• Netflix Hystrix: Circuit breaker and dashboard
• Netflix Turbine: Aggregate hystrix streams
73. © mimacom 30.03.2015
Summary
• Netflix Eureka: Service registry & discovery
• Netflix Hystrix: Circuit breaker and dashboard
• Netflix Turbine: Aggregate hystrix streams
• Netflix Ribbon: Client-side load-balancing
74. © mimacom 30.03.2015
Summary
• Netflix Eureka: Service registry & discovery
• Netflix Hystrix: Circuit breaker and dashboard
• Netflix Turbine: Aggregate hystrix streams
• Netflix Ribbon: Client-side load-balancing
• Netflix Zuul: Reverse proxy for API gateway
75. © mimacom 30.03.2015
Summary
• Netflix Eureka: Service registry & discovery
• Netflix Hystrix: Circuit breaker and dashboard
• Netflix Turbine: Aggregate hystrix streams
• Netflix Ribbon: Client-side load-balancing
• Netflix Zuul: Reverse proxy for API gateway
• Spring Cloud Config: Centralized configuration
76. © mimacom 30.03.2015
Summary
• Netflix Eureka: Service registry & discovery
• Netflix Hystrix: Circuit breaker and dashboard
• Netflix Turbine: Aggregate hystrix streams
• Netflix Ribbon: Client-side load-balancing
• Netflix Zuul: Reverse proxy for API gateway
• Spring Cloud Config: Centralized configuration
• Spring Cloud Bus: Publish events over RabbitMQ
77. © mimacom 30.03.2015
Summary
• Netflix Eureka: Service registry & discovery
• Netflix Hystrix: Circuit breaker and dashboard
• Netflix Turbine: Aggregate hystrix streams
• Netflix Ribbon: Client-side load-balancing
• Netflix Zuul: Reverse proxy for API gateway
• Spring Cloud Config: Centralized configuration
• Spring Cloud Bus: Publish events over RabbitMQ
• Spring Cloud Netflix: Configure Netflix components