building microservices with spring cloud and netflix oss

24
BUILDING MICROSERVICES WITH SPRING CLOUD AND NETFLIX OSS

Upload: semih-hakkioglu

Post on 22-Jan-2018

444 views

Category:

Software


1 download

TRANSCRIPT

Page 1: Building Microservices with Spring Cloud and Netflix OSS

BUILDING

MICROSERVICESWITH

SPRING CLOUDAND

NETFLIX OSS

Page 2: Building Microservices with Spring Cloud and Netflix OSS

AGENDA- Config Server

- Config Client

- Bus

- Eureka Server

- Eureka Client

- Zuul

- Feign

- Hystrix

- Hystrix Dashboard

Page 3: Building Microservices with Spring Cloud and Netflix OSS

Client

CC

EC

ZUUL

GATEWAY API

CONFIG

SERVER

EC

FEIGN

EC

INVOICE

SERVICE

CC

SERVICE

DISCOVE

RYES

HYSTRIX

DASHBOARD

FEIGN

EC

CC

MERCHANT

SERVICE

Page 4: Building Microservices with Spring Cloud and Netflix OSS

Service Discovery

- Maintains registry of clients with metadata

- Heartbeats (default 30 seconds)

- Dashboard

- Host/Port

- Health indicator url

Page 5: Building Microservices with Spring Cloud and Netflix OSS

Service DiscoveryApplication.java

@SpringBootApplication

@EnableEurekaServer

public class ServiceDiscoveryApplication {

public static void main(String[] args) {

SpringApplication.run(ServiceDiscoveryApplication.class, args);

}

}

Page 6: Building Microservices with Spring Cloud and Netflix OSS

Service Discoverybootstrap.yml

spring:

application:

name: service-discovery

server.port: ${PORT:8761}

eureka:

instance.hostname: localhost

client:

registerWithEureka: false

fetchRegistry: false

serviceUrl.defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/

Page 7: Building Microservices with Spring Cloud and Netflix OSS

DEMO

Page 8: Building Microservices with Spring Cloud and Netflix OSS

Config Server

Page 9: Building Microservices with Spring Cloud and Netflix OSS

Config ServerResource Format

- /{application}/{profile}/{label}

- /{application}-{profiles}.yml

- /{label}/{application}-{profiles}.yml

- /{application}-{profiles}.properties

- /{label}/{application}-{profiles}.properties

Page 10: Building Microservices with Spring Cloud and Netflix OSS

Config ServerApplication.java

@SpringBootApplication

@EnableConfigServer

@EnableEurekaClient

public class ConfigServerApplication {

public static void main(String[] args) {

SpringApplication.run(ConfigServerApplication.class, args);

}

}

Page 11: Building Microservices with Spring Cloud and Netflix OSS

spring:

application.name: config-server

cloud.config:

server.git.uri: https://github.com/semihhakkioglu/spring-cloud-microservice-config

label: develop

security.basic.enabled: false

management.security.enabled: false

server.port: ${PORT:8888}

eureka:

instance.hostname: localhost

client.serviceUrl.defaultZone: http://localhost:8761/eureka/

Config Serverbootstrap.yml

Page 12: Building Microservices with Spring Cloud and Netflix OSS

DEMO

Page 13: Building Microservices with Spring Cloud and Netflix OSS

Gateway APIZuul

- Filtering

- Load Balancing

- Provides single point of entry to service

- By default creates route for all registered service in Eureka

Server

- http://localhost:8080/merchant-service routes to merchant-

service

Page 14: Building Microservices with Spring Cloud and Netflix OSS

Gateway APIApplication.java

@SpringBootApplication

@EnableZuulProxy

@EnableEurekaClient

public class GatewayApiApplication {

public static void main(String[] args) {

SpringApplication.run(GatewayApiApplication.class, args);

}

}

Page 15: Building Microservices with Spring Cloud and Netflix OSS

Gateway APIbootstrap.yml

spring:

application:

name: gateway-api

cloud.config:

discovery.service-id: config-server

label: develop

server.port: ${PORT:8080}

eureka.client.serviceUrl.defaultZone: http://localhost:8761/eureka/

Page 16: Building Microservices with Spring Cloud and Netflix OSS

Gateway APIgateway-api.yml

ribbon:

ReadTimeout: 20000

ConnectTimeout: 20000

zuul:

routes:

ignoredService: '*'

invoice-service:

path: /invoices/**

serviceId: invoice-service

stripPrefix: false

merchant-service:

path: /merchants/**

serviceId: merchant-service

stripPrefix: true

Page 17: Building Microservices with Spring Cloud and Netflix OSS

DEMO

Page 18: Building Microservices with Spring Cloud and Netflix OSS

ServicesApplication.java

@SpringBootApplication

@EnableEurekaClient

@EnableFeignClients

@EnableCircuitBreaker

public class InvoiceServiceApplication {

public static void main(String[] args) {

SpringApplication.run(InvoiceServiceApplication.class, args);

}

}

Page 19: Building Microservices with Spring Cloud and Netflix OSS

Servicesbootstrap.yml

spring:

application:

name: invoice-service

cloud.config:

discovery.service-id: config-server

label: develop

server.port: ${PORT:9090}

eureka.client.serviceUrl.defaultZone: http://localhost:8761/eureka/

Page 20: Building Microservices with Spring Cloud and Netflix OSS

DEMO

Page 21: Building Microservices with Spring Cloud and Netflix OSS

Hystrix DashboardApplication.java

@SpringBootApplication

@EnableHystrixDashboard

@EnableEurekaClient

public class HystrixDashboardApplication {

public static void main(String[] args) {

SpringApplication.run(HystrixDashboardApplication.class, args);

}

}

Page 22: Building Microservices with Spring Cloud and Netflix OSS

Hystrix Dashboardbootstrap.yml

spring.application.name: hystrix-dashboard

server.port: ${PORT:8010}

eureka:

instance:

hostname: localhost

client:

registerWithEureka: true

fetchRegistry: true

serviceUrl:

defaultZone: http://localhost:8761/eureka/

Page 23: Building Microservices with Spring Cloud and Netflix OSS

DEMO

Page 24: Building Microservices with Spring Cloud and Netflix OSS

Semih HAKKIOĞLU

https://github.com/semihhakkioglu/spring-cloud-microservice-example

https://github.com/semihhakkioglu/spring-cloud-microservice-config

THANK YOU