spring cloud servicesの紹介 #pcf_tokyo

Post on 16-Apr-2017

1.473 Views

Category:

Technology

2 Downloads

Preview:

Click to see full reader

TRANSCRIPT

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

Spring Cloud ServicesToshiaki 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

RibbonZuul

Eureka

Zipkin

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

• Service RegistryRegistry

" (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@EnableConfigServerpublic class ConfigServerApplication { public static void main(String[] args) { SpringApplication.run(ConfigServerApplication.class, args); }}

👈

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

👈

‹#›© 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:8888spring.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@EnableEurekaServerpublic class EurekaServerApplication { public static void main(String[] args) { SpringApplication.run(EurekaServerApplication.class, args); }}

👈

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

👈

‹#›© 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@EnableDiscoveryClientpublic class RecommendationsApplication { public static void main(String[] args) { SpringApplication.run(RecommendationsApplication.class, args); }}

👈

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

👈

‹#›© 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@EnableCircuitBreakerpublic class RecommendationsApplication { public static void main(String[] args) { SpringApplication.run(RecommendationsApplication.class, args); }}

👈

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

👈

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

👈

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

👈

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

👈

👈

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

👈

👈

‹#›© 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@EnableHystrixDashboardpublic class HystrixDashboardApplication { public static void main(String[] args) { SpringApplication.run(HystrixDashboardApplication.class, args); }}

👈

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

👈

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

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

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

top related