‹#›© 2016 Pivotal Software, Inc. All rights reserved. ‹#›© 2016 Pivotal Software, Inc. All rights reserved.
Spring Cloud Services
Toshiaki Maki (@making)
PCF Meetup
2016-06-29
© 2016 Pivotal Software, Inc. All rights reserved.
Who am I ?
• Toshiaki Maki (@making)
• Sr. Solutions Architect
• Spring Framework enthusiast
Perfect
Java EE
(Coming Soon)
bit.ly/spring-book
‹#›© 2016 Pivotal Software, Inc. All rights reserved.
Spring Cloud
© 2016 Pivotal Software, Inc. All rights reserved.
Spring Cloud
• Omakase Microservices
© 2016 Pivotal Software, Inc. All rights reserved.
• Service Discovery
• API Gateway
• Client-side Load Balancing
• Circuit Breakers
• Distributed Configuration
• Distributed Tracing
Spring Cloud Provides
Hystrix
Ribbon
Zuul
Eureka
Zipkin
© 2016 Pivotal Software, Inc. All rights reserved.
• Service Registry

Registry 

• 

" (host )" 

" " ( )
• Registry 

• Service Discovery
• Eureka (Netflix)
• Consul (HashiCorp)
• Zookeeper
Service Discovery
© 2016 Pivotal Software, Inc. All rights reserved.
• Service Registry 





• Netflix Ribbon
Client-side Load Balancing
© 2016 Pivotal Software, Inc. All rights reserved.
• 



( )
• 

(Open) 



(Half-Open) 

(Closed)
• Netflix Hystrix
•
Circuit Breaker
© 2016 Pivotal Software, Inc. All rights reserved.
• 

REST API 

• 

• Git/Subversion/

Distributed Configuration
‹#›© 2016 Pivotal Software, Inc. All rights reserved.
Spring Cloud
© 2016 Pivotal Software, Inc. All rights reserved.
© 2016 Pivotal Software, Inc. All rights reserved.
© 2016 Pivotal Software, Inc. All rights reserved.
• Spring Boot
• Spring Cloud
• @EnableXxxServer
•
© 2016 Pivotal Software, Inc. All rights reserved.
Implement Config Server
© 2016 Pivotal Software, Inc. All rights reserved.
Add dependency
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
</dependency>
© 2016 Pivotal Software, Inc. All rights reserved.
Create Config Server
@SpringBootApplication
@EnableConfigServer
public class ConfigServerApplication {
public static void main(String[] args) {
SpringApplication.run(ConfigServerApplication.class, args);
}
}
👈
© 2016 Pivotal Software, Inc. All rights reserved.
Create Config Server
@SpringBootApplication
@EnableConfigServer
public class ConfigServerApplication {
public static void main(String[] args) {
SpringApplication.run(ConfigServerApplication.class, args);
}
}
👈
© 2016 Pivotal Software, Inc. All rights reserved.
Configure Config Server
spring.cloud.config.server.git.uri=https://github.com/
making/metflix-config.git
© 2016 Pivotal Software, Inc. All rights reserved.
Configure Config Client
© 2016 Pivotal Software, Inc. All rights reserved.
Add dependency
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
© 2016 Pivotal Software, Inc. All rights reserved.
Configure Config Client
spring.cloud.config.uri=http://localhost:8888
spring.application.name=membership
© 2016 Pivotal Software, Inc. All rights reserved.
© 2016 Pivotal Software, Inc. All rights reserved.
Implement Service Registry
© 2016 Pivotal Software, Inc. All rights reserved.
Add dependency
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka-server</artifactId>
</dependency>
© 2016 Pivotal Software, Inc. All rights reserved.
Create Eureka Server
@SpringBootApplication
@EnableEurekaServer
public class EurekaServerApplication {
public static void main(String[] args) {
SpringApplication.run(EurekaServerApplication.class,
args);
}
}
👈
© 2016 Pivotal Software, Inc. All rights reserved.
Create Eureka Server
@SpringBootApplication
@EnableEurekaServer
public class EurekaServerApplication {
public static void main(String[] args) {
SpringApplication.run(EurekaServerApplication.class,
args);
}
}
👈
© 2016 Pivotal Software, Inc. All rights reserved.
© 2016 Pivotal Software, Inc. All rights reserved.
Configure Discovery Clients
© 2016 Pivotal Software, Inc. All rights reserved.
Add dependency
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka</artifactId>
</dependency>
© 2016 Pivotal Software, Inc. All rights reserved.
Create Eureka Client
@SpringBootApplication
@EnableDiscoveryClient
public class RecommendationsApplication {
public static void main(String[] args) {
SpringApplication.run(RecommendationsApplication.class,
args);
}
}
👈
© 2016 Pivotal Software, Inc. All rights reserved.
Create Eureka Client
@SpringBootApplication
@EnableDiscoveryClient
public class RecommendationsApplication {
public static void main(String[] args) {
SpringApplication.run(RecommendationsApplication.class,
args);
}
}
👈
© 2016 Pivotal Software, Inc. All rights reserved.
© 2016 Pivotal Software, Inc. All rights reserved.
Introduce Circuit Breaker
© 2016 Pivotal Software, Inc. All rights reserved.
Add dependency
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-hystrix</artifactId>
</dependency>
© 2016 Pivotal Software, Inc. All rights reserved.
Use Hystrix
@SpringBootApplication
@EnableDiscoveryClient
@EnableCircuitBreaker
public class RecommendationsApplication {
public static void main(String[] args) {
SpringApplication.run(RecommendationsApplication.class,
args);
}
}
👈
© 2016 Pivotal Software, Inc. All rights reserved.
Use Hystrix
@SpringBootApplication
@EnableDiscoveryClient
@EnableCircuitBreaker
public class RecommendationsApplication {
public static void main(String[] args) {
SpringApplication.run(RecommendationsApplication.class,
args);
}
}
👈
© 2016 Pivotal Software, Inc. All rights reserved.
Configure Hystrix Command
@Component
public class RecommendationsService {
@HystrixCommand(fallbackMethod =
"recommendationFallback")
List<Movie> findRecommendationsForUser(String user) {
// some recommendation logic
}
List<Movie> recommendationFallback(String user) {
return top5Movies;
}
}
👈
© 2016 Pivotal Software, Inc. All rights reserved.
Configure Hystrix Command
@Component
public class RecommendationsService {
@HystrixCommand(fallbackMethod =
"recommendationFallback")
List<Movie> findRecommendationsForUser(String user) {
// some recommendation logic
}
List<Movie> recommendationFallback(String user) {
return top5Movies;
}
}
👈
© 2016 Pivotal Software, Inc. All rights reserved.
Configure Hystrix Command
@Component
public class RecommendationsService {
@HystrixCommand(fallbackMethod =
"recommendationFallback")
List<Movie> findRecommendationsForUser(String user) {
// some recommendation logic
}
List<Movie> recommendationFallback(String user) {
return top5Movies;
}
}
👈
👈
© 2016 Pivotal Software, Inc. All rights reserved.
Configure Hystrix Command
@Component
public class RecommendationsService {
@HystrixCommand(fallbackMethod =
"recommendationFallback")
List<Movie> findRecommendationsForUser(String user) {
// some recommendation logic
}
List<Movie> recommendationFallback(String user) {
return top5Movies;
}
}
👈
👈
© 2016 Pivotal Software, Inc. All rights reserved.
Implement Circuit Breaker Dashboard
© 2016 Pivotal Software, Inc. All rights reserved.
Add dependency
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-hystrix-dashboard</artifactId>
</dependency>
© 2016 Pivotal Software, Inc. All rights reserved.
Create Dashboard Server
@SpringBootApplication
@EnableHystrixDashboard
public class HystrixDashboardApplication {
public static void main(String[] args) {
SpringApplication.run(HystrixDashboardApplication.class,
args);
}
}
👈
© 2016 Pivotal Software, Inc. All rights reserved.
Create Dashboard Server
@SpringBootApplication
@EnableHystrixDashboard
public class HystrixDashboardApplication {
public static void main(String[] args) {
SpringApplication.run(HystrixDashboardApplication.class,
args);
}
}
👈
© 2016 Pivotal Software, Inc. All rights reserved.
© 2016 Pivotal Software, Inc. All rights reserved.
© 2016 Pivotal Software, Inc. All rights reserved.
Hystrix Dashboard
• 1 (=1 )
• Turbine
• Server-Sent Event pull PaaS
1URL
‹#›© 2016 Pivotal Software, Inc. All rights reserved.
Spring Cloud Services
© 2016 Pivotal Software, Inc. All rights reserved.
"Spring Cloud as a Service"
© 2016 Pivotal Software, Inc. All rights reserved.
• Spring Boot
• Spring Cloud
• @EnableXxxServer
•
•
•
© 2016 Pivotal Software, Inc. All rights reserved.
• Spring Boot
• Spring Cloud
• @EnableXxxServer
•
•
•
• cf create-service
© 2016 Pivotal Software, Inc. All rights reserved.
• Spring Boot
• Spring Cloud
•
•
© 2016 Pivotal Software, Inc. All rights reserved.
• Spring Boot
• Spring Cloud
•
•
• Spring Boot
• Spring Cloud Services
•
• cf bind-service
© 2016 Pivotal Software, Inc. All rights reserved.
© 2016 Pivotal Software, Inc. All rights reserved.
🔒 🔒 🔒
© 2016 Pivotal Software, Inc. All rights reserved.
🔒 🔒 🔒
OAuth2
© 2016 Pivotal Software, Inc. All rights reserved.
© 2016 Pivotal Software, Inc. All rights reserved.
© 2016 Pivotal Software, Inc. All rights reserved.
© 2016 Pivotal Software, Inc. All rights reserved.
Create services
cf create-service p-config-server standard config-server 
-c '{"git":{"uri":"https://github.com/making/metflix-config"}}'
cf create-service p-service-registry standard eureka-server
cf create-service p-circuit-breaker-dashboard standard 
hystrix-dashboard
© 2016 Pivotal Software, Inc. All rights reserved.
Bind Services
cf bind-service membership config-server
cf bind-service recommendations config-server
cf bind-service ui config-server
cf bind-service membership eureka-server
cf bind-service recommendations eureka-server
cf bind-service ui eureka-server
cf bind-service recommendations hystrix-dashboard
cf bind-service ui hystrix-dashboard
© 2016 Pivotal Software, Inc. All rights reserved.
© 2016 Pivotal Software, Inc. All rights reserved.
© 2016 Pivotal Software, Inc. All rights reserved.
© 2016 Pivotal Software, Inc. All rights reserved.
RabbitMQ push
!!
© 2016 Pivotal Software, Inc. All rights reserved.
• Spring Cloud r
• Spring Cloud Service = "Spring Cloud" as a service
• @EnableXxxServer --> cf create-service + OAuth2
© 2016 Pivotal Software, Inc. All rights reserved.
Links
• http://www.slideshare.net/SpringCentral/cloud-native-java-
with-spring-cloud-services
• https://github.com/Pivotal-Japan/cloud-native-workshop

Spring Cloud Servicesの紹介 #pcf_tokyo

  • 1.
    ‹#›© 2016 PivotalSoftware, Inc. All rights reserved. ‹#›© 2016 Pivotal Software, Inc. All rights reserved. Spring Cloud Services Toshiaki Maki (@making) PCF Meetup 2016-06-29
  • 2.
    © 2016 PivotalSoftware, Inc. All rights reserved. Who am I ? • Toshiaki Maki (@making) • Sr. Solutions Architect • Spring Framework enthusiast Perfect Java EE (Coming Soon) bit.ly/spring-book
  • 3.
    ‹#›© 2016 PivotalSoftware, Inc. All rights reserved. Spring Cloud
  • 4.
    © 2016 PivotalSoftware, Inc. All rights reserved. Spring Cloud • Omakase Microservices
  • 5.
    © 2016 PivotalSoftware, Inc. All rights reserved. • Service Discovery • API Gateway • Client-side Load Balancing • Circuit Breakers • Distributed Configuration • Distributed Tracing Spring Cloud Provides Hystrix Ribbon Zuul Eureka Zipkin
  • 6.
    © 2016 PivotalSoftware, Inc. All rights reserved. • Service Registry
 Registry 
 • 
 " (host )" 
 " " ( ) • Registry 
 • Service Discovery • Eureka (Netflix) • Consul (HashiCorp) • Zookeeper Service Discovery
  • 7.
    © 2016 PivotalSoftware, Inc. All rights reserved. • Service Registry 
 
 
 • Netflix Ribbon Client-side Load Balancing
  • 8.
    © 2016 PivotalSoftware, Inc. All rights reserved. • 
 
 ( ) • 
 (Open) 
 
 (Half-Open) 
 (Closed) • Netflix Hystrix • Circuit Breaker
  • 9.
    © 2016 PivotalSoftware, Inc. All rights reserved. • 
 REST API 
 • 
 • Git/Subversion/
 Distributed Configuration
  • 10.
    ‹#›© 2016 PivotalSoftware, Inc. All rights reserved. Spring Cloud
  • 11.
    © 2016 PivotalSoftware, Inc. All rights reserved.
  • 12.
    © 2016 PivotalSoftware, Inc. All rights reserved.
  • 13.
    © 2016 PivotalSoftware, Inc. All rights reserved. • Spring Boot • Spring Cloud • @EnableXxxServer •
  • 14.
    © 2016 PivotalSoftware, Inc. All rights reserved. Implement Config Server
  • 15.
    © 2016 PivotalSoftware, Inc. All rights reserved. Add dependency <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-config-server</artifactId> </dependency>
  • 16.
    © 2016 PivotalSoftware, Inc. All rights reserved. Create Config Server @SpringBootApplication @EnableConfigServer public class ConfigServerApplication { public static void main(String[] args) { SpringApplication.run(ConfigServerApplication.class, args); } } 👈
  • 17.
    © 2016 PivotalSoftware, Inc. All rights reserved. Create Config Server @SpringBootApplication @EnableConfigServer public class ConfigServerApplication { public static void main(String[] args) { SpringApplication.run(ConfigServerApplication.class, args); } } 👈
  • 18.
    © 2016 PivotalSoftware, Inc. All rights reserved. Configure Config Server spring.cloud.config.server.git.uri=https://github.com/ making/metflix-config.git
  • 19.
    © 2016 PivotalSoftware, Inc. All rights reserved. Configure Config Client
  • 20.
    © 2016 PivotalSoftware, Inc. All rights reserved. Add dependency <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-config</artifactId> </dependency>
  • 21.
    © 2016 PivotalSoftware, Inc. All rights reserved. Configure Config Client spring.cloud.config.uri=http://localhost:8888 spring.application.name=membership
  • 22.
    © 2016 PivotalSoftware, Inc. All rights reserved.
  • 23.
    © 2016 PivotalSoftware, Inc. All rights reserved. Implement Service Registry
  • 24.
    © 2016 PivotalSoftware, Inc. All rights reserved. Add dependency <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-eureka-server</artifactId> </dependency>
  • 25.
    © 2016 PivotalSoftware, Inc. All rights reserved. Create Eureka Server @SpringBootApplication @EnableEurekaServer public class EurekaServerApplication { public static void main(String[] args) { SpringApplication.run(EurekaServerApplication.class, args); } } 👈
  • 26.
    © 2016 PivotalSoftware, Inc. All rights reserved. Create Eureka Server @SpringBootApplication @EnableEurekaServer public class EurekaServerApplication { public static void main(String[] args) { SpringApplication.run(EurekaServerApplication.class, args); } } 👈
  • 27.
    © 2016 PivotalSoftware, Inc. All rights reserved.
  • 28.
    © 2016 PivotalSoftware, Inc. All rights reserved. Configure Discovery Clients
  • 29.
    © 2016 PivotalSoftware, Inc. All rights reserved. Add dependency <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-eureka</artifactId> </dependency>
  • 30.
    © 2016 PivotalSoftware, Inc. All rights reserved. Create Eureka Client @SpringBootApplication @EnableDiscoveryClient public class RecommendationsApplication { public static void main(String[] args) { SpringApplication.run(RecommendationsApplication.class, args); } } 👈
  • 31.
    © 2016 PivotalSoftware, Inc. All rights reserved. Create Eureka Client @SpringBootApplication @EnableDiscoveryClient public class RecommendationsApplication { public static void main(String[] args) { SpringApplication.run(RecommendationsApplication.class, args); } } 👈
  • 32.
    © 2016 PivotalSoftware, Inc. All rights reserved.
  • 33.
    © 2016 PivotalSoftware, Inc. All rights reserved. Introduce Circuit Breaker
  • 34.
    © 2016 PivotalSoftware, Inc. All rights reserved. Add dependency <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-hystrix</artifactId> </dependency>
  • 35.
    © 2016 PivotalSoftware, Inc. All rights reserved. Use Hystrix @SpringBootApplication @EnableDiscoveryClient @EnableCircuitBreaker public class RecommendationsApplication { public static void main(String[] args) { SpringApplication.run(RecommendationsApplication.class, args); } } 👈
  • 36.
    © 2016 PivotalSoftware, Inc. All rights reserved. Use Hystrix @SpringBootApplication @EnableDiscoveryClient @EnableCircuitBreaker public class RecommendationsApplication { public static void main(String[] args) { SpringApplication.run(RecommendationsApplication.class, args); } } 👈
  • 37.
    © 2016 PivotalSoftware, Inc. All rights reserved. Configure Hystrix Command @Component public class RecommendationsService { @HystrixCommand(fallbackMethod = "recommendationFallback") List<Movie> findRecommendationsForUser(String user) { // some recommendation logic } List<Movie> recommendationFallback(String user) { return top5Movies; } } 👈
  • 38.
    © 2016 PivotalSoftware, Inc. All rights reserved. Configure Hystrix Command @Component public class RecommendationsService { @HystrixCommand(fallbackMethod = "recommendationFallback") List<Movie> findRecommendationsForUser(String user) { // some recommendation logic } List<Movie> recommendationFallback(String user) { return top5Movies; } } 👈
  • 39.
    © 2016 PivotalSoftware, Inc. All rights reserved. Configure Hystrix Command @Component public class RecommendationsService { @HystrixCommand(fallbackMethod = "recommendationFallback") List<Movie> findRecommendationsForUser(String user) { // some recommendation logic } List<Movie> recommendationFallback(String user) { return top5Movies; } } 👈 👈
  • 40.
    © 2016 PivotalSoftware, Inc. All rights reserved. Configure Hystrix Command @Component public class RecommendationsService { @HystrixCommand(fallbackMethod = "recommendationFallback") List<Movie> findRecommendationsForUser(String user) { // some recommendation logic } List<Movie> recommendationFallback(String user) { return top5Movies; } } 👈 👈
  • 41.
    © 2016 PivotalSoftware, Inc. All rights reserved. Implement Circuit Breaker Dashboard
  • 42.
    © 2016 PivotalSoftware, Inc. All rights reserved. Add dependency <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-hystrix-dashboard</artifactId> </dependency>
  • 43.
    © 2016 PivotalSoftware, Inc. All rights reserved. Create Dashboard Server @SpringBootApplication @EnableHystrixDashboard public class HystrixDashboardApplication { public static void main(String[] args) { SpringApplication.run(HystrixDashboardApplication.class, args); } } 👈
  • 44.
    © 2016 PivotalSoftware, Inc. All rights reserved. Create Dashboard Server @SpringBootApplication @EnableHystrixDashboard public class HystrixDashboardApplication { public static void main(String[] args) { SpringApplication.run(HystrixDashboardApplication.class, args); } } 👈
  • 45.
    © 2016 PivotalSoftware, Inc. All rights reserved.
  • 46.
    © 2016 PivotalSoftware, Inc. All rights reserved.
  • 47.
    © 2016 PivotalSoftware, Inc. All rights reserved. Hystrix Dashboard • 1 (=1 ) • Turbine • Server-Sent Event pull PaaS 1URL
  • 48.
    ‹#›© 2016 PivotalSoftware, Inc. All rights reserved. Spring Cloud Services
  • 49.
    © 2016 PivotalSoftware, Inc. All rights reserved. "Spring Cloud as a Service"
  • 50.
    © 2016 PivotalSoftware, Inc. All rights reserved. • Spring Boot • Spring Cloud • @EnableXxxServer • • •
  • 51.
    © 2016 PivotalSoftware, Inc. All rights reserved. • Spring Boot • Spring Cloud • @EnableXxxServer • • • • cf create-service
  • 52.
    © 2016 PivotalSoftware, Inc. All rights reserved. • Spring Boot • Spring Cloud • •
  • 53.
    © 2016 PivotalSoftware, Inc. All rights reserved. • Spring Boot • Spring Cloud • • • Spring Boot • Spring Cloud Services • • cf bind-service
  • 54.
    © 2016 PivotalSoftware, Inc. All rights reserved.
  • 55.
    © 2016 PivotalSoftware, Inc. All rights reserved. 🔒 🔒 🔒
  • 56.
    © 2016 PivotalSoftware, Inc. All rights reserved. 🔒 🔒 🔒 OAuth2
  • 57.
    © 2016 PivotalSoftware, Inc. All rights reserved.
  • 58.
    © 2016 PivotalSoftware, Inc. All rights reserved.
  • 59.
    © 2016 PivotalSoftware, Inc. All rights reserved.
  • 60.
    © 2016 PivotalSoftware, Inc. All rights reserved. Create services cf create-service p-config-server standard config-server -c '{"git":{"uri":"https://github.com/making/metflix-config"}}' cf create-service p-service-registry standard eureka-server cf create-service p-circuit-breaker-dashboard standard hystrix-dashboard
  • 61.
    © 2016 PivotalSoftware, Inc. All rights reserved. Bind Services cf bind-service membership config-server cf bind-service recommendations config-server cf bind-service ui config-server cf bind-service membership eureka-server cf bind-service recommendations eureka-server cf bind-service ui eureka-server cf bind-service recommendations hystrix-dashboard cf bind-service ui hystrix-dashboard
  • 62.
    © 2016 PivotalSoftware, Inc. All rights reserved.
  • 63.
    © 2016 PivotalSoftware, Inc. All rights reserved.
  • 64.
    © 2016 PivotalSoftware, Inc. All rights reserved.
  • 65.
    © 2016 PivotalSoftware, Inc. All rights reserved. RabbitMQ push !!
  • 66.
    © 2016 PivotalSoftware, Inc. All rights reserved. • Spring Cloud r • Spring Cloud Service = "Spring Cloud" as a service • @EnableXxxServer --> cf create-service + OAuth2
  • 67.
    © 2016 PivotalSoftware, Inc. All rights reserved. Links • http://www.slideshare.net/SpringCentral/cloud-native-java- with-spring-cloud-services • https://github.com/Pivotal-Japan/cloud-native-workshop