Spring Cloud - studiofu/brain GitHub Wiki
-
Registry and Discovery - Eureka
- Depending on the spring-cloud-starter-eureka-server
- add @EnableEurekaServer to enable the server
- add @EnableDiscoveryClient to enable Eureka client
- create more than one Eureka servers and register each others and enable high availability.
- in the client side, it's required to add more than one registry server url in the eureka.client.serviceUrl.defaultZone
- https://www.jianshu.com/p/12a70993e321
- alterative: https://nacos.io/en-us/docs/quick-start-spring-cloud.html
-
Consumption - Robbin
- use Ribbon - https://www.baeldung.com/spring-cloud-rest-client-with-netflix-ribbon
- need to add the dependency spring-cloud-starter-ribbon
- RestTemplate
- restTemplate.getForEntity, return ResponseEntity
-
Spring Cloud Hystrix
- implement the circuit breaker
- add spring-cloud-starter-hystrix
- add @EnableCircuitBreaker to Application Class
- add @@HystrixCommand to the method and define the fallbackMethod for handling the circuit break
- add cache ← need more study
- add batch call - HystrixCollapser ← need more study
-
Spring Cloud Feign
- encapsulated the RestTemplate and just use the service
- need to define the feign client interface by adding @FeignClient and then specify the service name
- it is able to define the fallback method in the class level by applying the fallback = “{class}”
-
Spring Cloud Zuul
- define url mapping in the application properties
- zuul.routes.api-a.path=/api-a/{}{}
- zuul.routes.api-a.serviceId=hello-service
- zuul.routes.api-a-url.path=/api-a-url/{}{}
- zuul.routes.api-a-url.url=http://localhost:8080/
- can define filter to pre-processing
- extends ZuulFilter
- https://www.cnblogs.com/hyhnet/p/8097641.html
-
Spring Bus
- use rabbitMQ
- define connection in application properties
- create Queue bean in @Configuration
- use AmqpTemplate to send the message to the queue
- template.convertAndSend(“hello”,“message”)
- send to hello queue
Handle Security in Zuul, with OAuth2 and JWT
https://www.baeldung.com/spring-security-zuul-oauth-jwt
Spring Cloud下基于OAUTH2认证授权的实现