building microservices with spring cloud and netflix oss

Post on 22-Jan-2018

444 Views

Category:

Software

1 Downloads

Preview:

Click to see full reader

TRANSCRIPT

BUILDING

MICROSERVICESWITH

SPRING CLOUDAND

NETFLIX OSS

AGENDA- Config Server

- Config Client

- Bus

- Eureka Server

- Eureka Client

- Zuul

- Feign

- Hystrix

- Hystrix Dashboard

Client

CC

EC

ZUUL

GATEWAY API

CONFIG

SERVER

EC

FEIGN

EC

INVOICE

SERVICE

CC

SERVICE

DISCOVE

RYES

HYSTRIX

DASHBOARD

FEIGN

EC

CC

MERCHANT

SERVICE

Service Discovery

- Maintains registry of clients with metadata

- Heartbeats (default 30 seconds)

- Dashboard

- Host/Port

- Health indicator url

Service DiscoveryApplication.java

@SpringBootApplication

@EnableEurekaServer

public class ServiceDiscoveryApplication {

public static void main(String[] args) {

SpringApplication.run(ServiceDiscoveryApplication.class, args);

}

}

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/

DEMO

Config Server

Config ServerResource Format

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

- /{application}-{profiles}.yml

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

- /{application}-{profiles}.properties

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

Config ServerApplication.java

@SpringBootApplication

@EnableConfigServer

@EnableEurekaClient

public class ConfigServerApplication {

public static void main(String[] args) {

SpringApplication.run(ConfigServerApplication.class, args);

}

}

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

DEMO

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

Gateway APIApplication.java

@SpringBootApplication

@EnableZuulProxy

@EnableEurekaClient

public class GatewayApiApplication {

public static void main(String[] args) {

SpringApplication.run(GatewayApiApplication.class, args);

}

}

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/

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

DEMO

ServicesApplication.java

@SpringBootApplication

@EnableEurekaClient

@EnableFeignClients

@EnableCircuitBreaker

public class InvoiceServiceApplication {

public static void main(String[] args) {

SpringApplication.run(InvoiceServiceApplication.class, args);

}

}

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/

DEMO

Hystrix DashboardApplication.java

@SpringBootApplication

@EnableHystrixDashboard

@EnableEurekaClient

public class HystrixDashboardApplication {

public static void main(String[] args) {

SpringApplication.run(HystrixDashboardApplication.class, args);

}

}

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/

DEMO

Semih HAKKIOĞLU

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

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

THANK YOU

top related