spring cloud servicesの紹介 #pcf_tokyo

67
‹#› © 2016 Pivotal Software, Inc. All rights reserved. Spring Cloud Services Toshiaki Maki (@making) PCF Meetup 2016-06-29

Upload: toshiaki-maki

Post on 16-Apr-2017

1.473 views

Category:

Technology


2 download

TRANSCRIPT

Page 1: Spring Cloud Servicesの紹介 #pcf_tokyo

‹#›© 2016 Pivotal Software, Inc. All rights reserved. ‹#›© 2016 Pivotal Software, Inc. All rights reserved.

Spring Cloud ServicesToshiaki Maki (@making) PCF Meetup 2016-06-29

Page 2: Spring Cloud Servicesの紹介 #pcf_tokyo

‹#›© 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

Page 3: Spring Cloud Servicesの紹介 #pcf_tokyo

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

Spring Cloud

Page 4: Spring Cloud Servicesの紹介 #pcf_tokyo

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

Spring Cloud•Omakase Microservices

Page 5: Spring Cloud Servicesの紹介 #pcf_tokyo

‹#›© 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

RibbonZuul

Eureka

Zipkin

Page 6: Spring Cloud Servicesの紹介 #pcf_tokyo

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

• Service RegistryRegistry

" (host )" " " ( ) • Registry

• Service Discovery •Eureka (Netflix) •Consul (HashiCorp) •Zookeeper

Service Discovery

Page 7: Spring Cloud Servicesの紹介 #pcf_tokyo

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

•Service Registry

•Netflix Ribbon

Client-side Load Balancing

Page 8: Spring Cloud Servicesの紹介 #pcf_tokyo

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

( ) •

(Open)

(Half-Open) (Closed)

•Netflix Hystrix •

Circuit Breaker

Page 9: Spring Cloud Servicesの紹介 #pcf_tokyo

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

• REST API

• Git/Subversion/

Distributed Configuration

Page 10: Spring Cloud Servicesの紹介 #pcf_tokyo

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

Spring Cloud

Page 11: Spring Cloud Servicesの紹介 #pcf_tokyo

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

Page 12: Spring Cloud Servicesの紹介 #pcf_tokyo

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

Page 13: Spring Cloud Servicesの紹介 #pcf_tokyo

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

•Spring Boot

•Spring Cloud

• @EnableXxxServer•

Page 14: Spring Cloud Servicesの紹介 #pcf_tokyo

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

Implement Config Server

Page 15: Spring Cloud Servicesの紹介 #pcf_tokyo

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

Add dependency

<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-config-server</artifactId></dependency>

Page 16: Spring Cloud Servicesの紹介 #pcf_tokyo

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

Create Config Server

@SpringBootApplication@EnableConfigServerpublic class ConfigServerApplication { public static void main(String[] args) { SpringApplication.run(ConfigServerApplication.class, args); }}

👈

Page 17: Spring Cloud Servicesの紹介 #pcf_tokyo

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

Create Config Server

@SpringBootApplication@EnableConfigServerpublic class ConfigServerApplication { public static void main(String[] args) { SpringApplication.run(ConfigServerApplication.class, args); }}

👈

Page 18: Spring Cloud Servicesの紹介 #pcf_tokyo

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

Configure Config Server

spring.cloud.config.server.git.uri=https://github.com/making/metflix-config.git

Page 19: Spring Cloud Servicesの紹介 #pcf_tokyo

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

Configure Config Client

Page 20: Spring Cloud Servicesの紹介 #pcf_tokyo

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

Add dependency

<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-config</artifactId></dependency>

Page 21: Spring Cloud Servicesの紹介 #pcf_tokyo

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

Configure Config Client

spring.cloud.config.uri=http://localhost:8888spring.application.name=membership

Page 22: Spring Cloud Servicesの紹介 #pcf_tokyo

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

Page 23: Spring Cloud Servicesの紹介 #pcf_tokyo

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

Implement Service Registry

Page 24: Spring Cloud Servicesの紹介 #pcf_tokyo

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

Add dependency

<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-eureka-server</artifactId></dependency>

Page 25: Spring Cloud Servicesの紹介 #pcf_tokyo

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

Create Eureka Server@SpringBootApplication@EnableEurekaServerpublic class EurekaServerApplication { public static void main(String[] args) { SpringApplication.run(EurekaServerApplication.class, args); }}

👈

Page 26: Spring Cloud Servicesの紹介 #pcf_tokyo

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

Create Eureka Server@SpringBootApplication@EnableEurekaServerpublic class EurekaServerApplication { public static void main(String[] args) { SpringApplication.run(EurekaServerApplication.class, args); }}

👈

Page 27: Spring Cloud Servicesの紹介 #pcf_tokyo

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

Page 28: Spring Cloud Servicesの紹介 #pcf_tokyo

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

Configure Discovery Clients

Page 29: Spring Cloud Servicesの紹介 #pcf_tokyo

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

Add dependency

<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-eureka</artifactId></dependency>

Page 30: Spring Cloud Servicesの紹介 #pcf_tokyo

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

Create Eureka Client

@SpringBootApplication@EnableDiscoveryClientpublic class RecommendationsApplication { public static void main(String[] args) { SpringApplication.run(RecommendationsApplication.class, args); }}

👈

Page 31: Spring Cloud Servicesの紹介 #pcf_tokyo

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

Create Eureka Client

@SpringBootApplication@EnableDiscoveryClientpublic class RecommendationsApplication { public static void main(String[] args) { SpringApplication.run(RecommendationsApplication.class, args); }}

👈

Page 32: Spring Cloud Servicesの紹介 #pcf_tokyo

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

Page 33: Spring Cloud Servicesの紹介 #pcf_tokyo

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

Introduce Circuit Breaker

Page 34: Spring Cloud Servicesの紹介 #pcf_tokyo

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

Add dependency

<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-hystrix</artifactId></dependency>

Page 35: Spring Cloud Servicesの紹介 #pcf_tokyo

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

Use Hystrix@SpringBootApplication@EnableDiscoveryClient@EnableCircuitBreakerpublic class RecommendationsApplication { public static void main(String[] args) { SpringApplication.run(RecommendationsApplication.class, args); }}

👈

Page 36: Spring Cloud Servicesの紹介 #pcf_tokyo

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

Use Hystrix@SpringBootApplication@EnableDiscoveryClient@EnableCircuitBreakerpublic class RecommendationsApplication { public static void main(String[] args) { SpringApplication.run(RecommendationsApplication.class, args); }}

👈

Page 37: Spring Cloud Servicesの紹介 #pcf_tokyo

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

Configure Hystrix Command@Componentpublic class RecommendationsService { @HystrixCommand(fallbackMethod = "recommendationFallback") List<Movie> findRecommendationsForUser(String user) { // some recommendation logic } List<Movie> recommendationFallback(String user) { return top5Movies; }}

👈

Page 38: Spring Cloud Servicesの紹介 #pcf_tokyo

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

Configure Hystrix Command@Componentpublic class RecommendationsService { @HystrixCommand(fallbackMethod = "recommendationFallback") List<Movie> findRecommendationsForUser(String user) { // some recommendation logic } List<Movie> recommendationFallback(String user) { return top5Movies; }}

👈

Page 39: Spring Cloud Servicesの紹介 #pcf_tokyo

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

Configure Hystrix Command@Componentpublic class RecommendationsService { @HystrixCommand(fallbackMethod = "recommendationFallback") List<Movie> findRecommendationsForUser(String user) { // some recommendation logic } List<Movie> recommendationFallback(String user) { return top5Movies; }}

👈

👈

Page 40: Spring Cloud Servicesの紹介 #pcf_tokyo

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

Configure Hystrix Command@Componentpublic class RecommendationsService { @HystrixCommand(fallbackMethod = "recommendationFallback") List<Movie> findRecommendationsForUser(String user) { // some recommendation logic } List<Movie> recommendationFallback(String user) { return top5Movies; }}

👈

👈

Page 41: Spring Cloud Servicesの紹介 #pcf_tokyo

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

Implement Circuit Breaker Dashboard

Page 42: Spring Cloud Servicesの紹介 #pcf_tokyo

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

Add dependency

<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-hystrix-dashboard</artifactId></dependency>

Page 43: Spring Cloud Servicesの紹介 #pcf_tokyo

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

Create Dashboard Server@SpringBootApplication@EnableHystrixDashboardpublic class HystrixDashboardApplication { public static void main(String[] args) { SpringApplication.run(HystrixDashboardApplication.class, args); }}

👈

Page 44: Spring Cloud Servicesの紹介 #pcf_tokyo

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

Create Dashboard Server@SpringBootApplication@EnableHystrixDashboardpublic class HystrixDashboardApplication { public static void main(String[] args) { SpringApplication.run(HystrixDashboardApplication.class, args); }}

👈

Page 45: Spring Cloud Servicesの紹介 #pcf_tokyo

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

Page 46: Spring Cloud Servicesの紹介 #pcf_tokyo

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

Page 47: Spring Cloud Servicesの紹介 #pcf_tokyo

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

Hystrix Dashboard • 1 (=1 )

• Turbine

•Server-Sent Event pull PaaS1URL

Page 48: Spring Cloud Servicesの紹介 #pcf_tokyo

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

Spring Cloud Services

Page 49: Spring Cloud Servicesの紹介 #pcf_tokyo

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

"Spring Cloud as a Service"

Page 50: Spring Cloud Servicesの紹介 #pcf_tokyo

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

•Spring Boot

•Spring Cloud

• @EnableXxxServer•

Page 51: Spring Cloud Servicesの紹介 #pcf_tokyo

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

•Spring Boot

•Spring Cloud

• @EnableXxxServer•

• cf create-service

Page 52: Spring Cloud Servicesの紹介 #pcf_tokyo

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

•Spring Boot

•Spring Cloud

Page 53: Spring Cloud Servicesの紹介 #pcf_tokyo

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

•Spring Boot

•Spring Cloud

•Spring Boot

•Spring Cloud Services

• cf bind-service

Page 54: Spring Cloud Servicesの紹介 #pcf_tokyo

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

Page 55: Spring Cloud Servicesの紹介 #pcf_tokyo

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

🔒 🔒🔒

Page 56: Spring Cloud Servicesの紹介 #pcf_tokyo

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

🔒 🔒🔒

OAuth2

Page 57: Spring Cloud Servicesの紹介 #pcf_tokyo

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

Page 58: Spring Cloud Servicesの紹介 #pcf_tokyo

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

Page 59: Spring Cloud Servicesの紹介 #pcf_tokyo

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

Page 60: Spring Cloud Servicesの紹介 #pcf_tokyo

‹#›© 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

Page 61: Spring Cloud Servicesの紹介 #pcf_tokyo

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

Bind Servicescf bind-service membership config-servercf bind-service recommendations config-servercf bind-service ui config-server

cf bind-service membership eureka-servercf bind-service recommendations eureka-servercf bind-service ui eureka-server

cf bind-service recommendations hystrix-dashboardcf bind-service ui hystrix-dashboard

Page 62: Spring Cloud Servicesの紹介 #pcf_tokyo

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

Page 63: Spring Cloud Servicesの紹介 #pcf_tokyo

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

Page 64: Spring Cloud Servicesの紹介 #pcf_tokyo

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

Page 65: Spring Cloud Servicesの紹介 #pcf_tokyo

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

RabbitMQ push

!!

Page 66: Spring Cloud Servicesの紹介 #pcf_tokyo

‹#›© 2016 Pivotal Software, Inc. All rights reserved.

•Spring Cloud r

•Spring Cloud Service = "Spring Cloud" as a service

• @EnableXxxServer --> cf create-service + OAuth2

Page 67: Spring Cloud Servicesの紹介 #pcf_tokyo

‹#›© 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