Ports
Application | Port |
---|---|
Limits Service | 8080, 8081, ... |
Spring Cloud Config Server | 8888 |
Currency Exchange Service | 8000, 8001, 8002, .. |
Currency Conversion Service | 8100, 8101, 8102, ... |
Netflix Eureka Naming Server | 8761 |
Netflix Zuul API Gateway Server | 8765 |
Zipkin Distributed Tracing Server | 9411 |
URLs
Application | URL |
---|---|
Limits Service | http://localhost:8080/limits POST -> http://localhost:8080/actuator/refresh |
Spring Cloud Config Server | http://localhost:8888/limits-service/default http://localhost:8888/limits-service/dev |
Currency Converter Service - Direct Call | http://localhost:8100/currency-converter/from/USD/to/INR/quantity/10 |
Currency Converter Service - Feign | http://localhost:8100/currency-converter-feign/from/EUR/to/INR/quantity/10000 |
Currency Exchange Service | http://localhost:8000/currency-exchange/from/EUR/to/INR http://localhost:8001/currency-exchange/from/USD/to/INR |
Eureka | http://localhost:8761/ |
Zuul - Currency Exchange & Exchange Services | http://localhost:8765/currency-exchange-service/currency-exchange/from/EUR/to/INR http://localhost:8765/currency-conversion-service/ currency-converter-feign/from/USD/to/INR/quantity/10 |
Zipkin | http://localhost:9411/zipkin/ |
Spring Cloud Bus Refresh | http://localhost:8080/bus/refresh |
Git :
/03.microservices/git-localconfig-repo/limits-service.properties
limits-service.minimum=8
limits-service.maximum=888
management.endpoints.web.exposure.include=*
Step 1 : Create a Centralized Microservice Configuration with Spring Cloud Config Server
Dependency : spring-cloud-config-server
Annotation : @EnableConfigServer
application.properties :
spring.application.name=spring-cloud-config-server
server.port=8888
spring.cloud.config.server.git.uri=file:///in28Minutes/git/spring-micro-services/03.microservices/git-localconfig-repo
For Fetching data from this config server add the following in bootstrap.properties for the respective service :
spring.application.name=limits-service
spring.cloud.config.uri=http://localhost:8888
spring.profiles.active=qa
management.endpoints.web.exposure.include=*
For Fetching data from this config server add the following in bootstrap.properties for the respective service :
spring.application.name=limits-service
spring.cloud.config.uri=http://localhost:8888
spring.profiles.active=qa
management.endpoints.web.exposure.include=*
Step 2 : Using Spring Cloud Bus to exchange messages about Configuration updates
Implementing a refresh URL to dynamically load properties without restarting respective services.
Dependency : spring-cloud-starter-bus-amqp (to be included in all projects which needs to be interconnected.)
URL : http://localhost:8080/bus/refresh
Refresh one url, rest all will receive refresh message from rabbitmq or Spring Cloud bus.
Step 3 : Implementing Eureka Server
Dependency : spring-cloud-starter-netflix-eureka-server
Annotation : @EnableEurekaServer
application.properties :
spring.application.name=netflix-eureka-naming-server
server.port=8761
eureka.client.register-with-eureka=false
eureka.client.fetch-registry=false
Step 4: Implementing API Gateway with Zuul
Dependency : spring-cloud-starter-netflix-zuul
Annotation :
@EnableZuulProxy
@EnableDiscoveryClient
application.properties :
spring.application.name=netflix-zuul-api-gateway-server
server.port=8765
eureka.client.service-url.default-zone=http://localhost:8761/eureka
Step 5 : Implementing Services : Conversion Service -> Exchange Service
Annotation: @EnableDiscoveryClient , @EnableFeignClients("com.in28minutes.microservices.currencyconversionservice")
PS: Create a proxy for calling exchange service from conversion service with automatic detection :
@FeignClient(name="netflix-zuul-api-gateway-server")
@RibbonClient(name="currency-exchange-service")
@FeignClient(name="netflix-zuul-api-gateway-server")
@RibbonClient(name="currency-exchange-service")
Step 6 : Enable Distributed Tracing via Zipking and Sleuth
Add Following Bean in gateway + all services :
@Bean
public Sampler defaultSampler(){
return Sampler.ALWAYS_SAMPLE;
}
Plus the following dependency :
<dependency>
Plus the following dependency :
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-sleuth</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-sleuth-zipkin</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bus-amqp</artifactId>
</dependency>
Step 6.1 : Install rabbit mq and zipkin server.
Step 6.2 : Start a zipkin server :
Annotation : @EnableZipkinServer
dependency :
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-sleuth-zipkin-stream</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-stream-rabbit</artifactId>
</dependency>
<dependency>
<groupId>io.zipkin.java</groupId>
<artifactId>zipkin-autoconfigure-ui</artifactId>
<scope>runtime</scope>
</dependency>
application.properties :
spring.application.name=zipkin-distributed-tracing-server
server.port=9411
Step 7: Implementing Fault Tolerance with Hysterix
Annotation : @EnableHystrix
@HystrixCommand(fallbackMethod="fallbackRetrieveConfiguration")
dependency :
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
</dependency>
Annotation : @EnableHystrix
@HystrixCommand(fallbackMethod="fallbackRetrieveConfiguration")
dependency :
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
</dependency>
Ref : https://github.com/in28minutes/spring-microservices/tree/master/03.microservices
No comments:
Post a Comment