Documentation content changes: add circuitbreaker readme (#930)

pull/923/head
Shanyou Yu (Sean Yu) 2 years ago committed by GitHub
parent 4e37401baa
commit 7fb60f8334
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -8,3 +8,4 @@
- [fix:optimize multi service registration and discovery.](https://github.com/Tencent/spring-cloud-tencent/pull/912)
- [feature: improve circuit breaker usage.](https://github.com/Tencent/spring-cloud-tencent/pull/913)
- [fix:fix nacos and consul registration.](https://github.com/Tencent/spring-cloud-tencent/pull/921)
- [Documentation content changes: add circuitbreaker readme.](https://github.com/Tencent/spring-cloud-tencent/pull/930)

@ -1,27 +1,24 @@
# Spring Cloud Polaris CircuitBreaker Example
# Spring Cloud Polaris Circuitbreaker example
## 样例简介
本样例将介绍如何在Spring Cloud项目中使用```spring-cloud-starter-tencent-polaris-circuitbreaker```以使用其各项功能。
该样例分为两个微服务,即
1. ```polaris-circuitbreaker-example-a```
2. ```polaris-circuitbreaker-example-b``` 有两个实例 B默认正常服务和 B2模拟异常服务
``` polaris-circuitbreaker-example-a``` 对 ```polaris-circuitbreaker-example-b```发生调用。
本样例包括被调方```polaris-circuitbreaker-callee-service```、```polaris-circuitbreaker-callee-service2```和主调方```polaris-circuitbreaker-feign-example```、```polaris-circuitbreaker-gateway-example```、```polaris-circuitbreaker-webclient-example```。
## 使用说明
### 修改配置
修改 resource/bootstrap.yml 中北极星的服务端地址
配置如下所示。其中,${ip}和${port}为Polaris后端服务的IP地址与端口号。
```yaml
spring:
application:
name: ${application.name}
cloud:
polaris:
address: grpc://${ip}:8091
address: ${ip}:${port}
```
### 启动样例
@ -30,43 +27,40 @@ spring:
参考[Polaris Getting Started](https://github.com/PolarisMesh/polaris#getting-started)。
### 启动应用
#### 启动被调应用
- IDEA启动
分别启动```polaris-circuitbreaker-example/polaris-circuitbreaker-callee-service```、```polaris-circuitbreaker-example/polaris-circuitbreaker-callee-service2```
分别启动
1. ```spring-cloud-tencent-examples/polaris-circuitbreaker-example/polaris-circuitbreaker-example-a```下的```ServiceA```
2. ```spring-cloud-tencent-examples/polaris-circuitbreaker-example/polaris-circuitbreaker-example-b```下的```ServiceB```
3. ```spring-cloud-tencent-examples/polaris-circuitbreaker-example/polaris-circuitbreaker-example-b2```下的```ServiceB2```
#### 启动主调应用
##### 启动Feign并验证
## 验证
启动```polaris-circuitbreaker-example/polaris-circuitbreaker-feign-example```。
### Feign调用
发送请求`curl --location --request GET 'http://127.0.0.1:48080/example/service/a/getBServiceInfo/fallbackFromPolaris'`, 验证熔断和Polaris-server远程拉取降级。
执行以下命令发起Feign调用其逻辑为```ServiceB```抛出一个异常
发送请求`curl --location --request GET 'http://127.0.0.1:48080/example/service/a/getBServiceInfo/fallbackFromCode'`, 验证熔断和代码降级。
```shell
curl -L -X GET 'localhost:48080/example/service/a/getBServiceInfo'
```
##### 启动RestTemplate并验证
预期返回情况:
启动```polaris-circuitbreaker-example/polaris-circuitbreaker-resttemplate-example```。
在出现
```
hello world ! I'm a service B1
```
发送请求`curl --location --request GET 'http://127.0.0.1:48080/example/service/a/getBServiceInfo/fallbackFromPolaris'`, 验证熔断和Polaris-server远程拉取降级。
发送请求`curl --location --request GET 'http://127.0.0.1:48080/example/service/a/getBServiceInfo/fallbackFromCode'`, 验证熔断和代码降级。
##### 启动WebClient并验证
启动```polaris-circuitbreaker-example/polaris-circuitbreaker-webclient-example```。
发送请求`curl --location --request GET 'http://127.0.0.1:48080/example/service/a/getBServiceInfo'`, 验证熔断和代码降级。
时,表示 B2 已经被熔断了,请求只会打到 B1。
##### 启动SCG并验证
### 验证更多场景
启动```polaris-circuitbreaker-example/polaris-circuitbreaker-gateway-example```。
您也可以调整 ```example-b``` 和 ```example-b2``` 中 ```resource/bootstrap.yml``` is-throw-runtime-exception
参数调整服务是否抛出异常。
发送请求`curl --location --request GET 'http://127.0.0.1:48080/polaris-circuitbreaker-callee-service/example/service/b/info'`, 验证熔断和代码降级。
例如测试以下场景:
1. 两个实例都是正常的,这时候预期是 B1 和 B2 都能正常被调用到
2. 一个实例正常一个实例不正常,这时候预期是不正常实例被熔断,请求只会打到正常的实例
3. 两个实例都不正常,这时候 Feign 会自动 Fallback 到 ProviderBFallback.java 的实现类
修改```polaris-circuitbreaker-example/polaris-circuitbreaker-gateway-example/resources/bootstrap.yml```。删除本地fallback方法并重启验证熔断和Polaris-server远程拉取降级。

@ -1,10 +1,10 @@
# Spring Cloud Polaris CircuitBreaker Example
# Spring Cloud Polaris Circuitbreaker example
## Example Introduction
This example shows how to use```spring-cloud-starter-tencent-polaris-circuitbreaker``` in Spring Cloud project and other features
This example shows how to use```spring-cloud-starter-tencent-polaris-circuitbreaker```in Spring Cloud project for its features.
This example is divided to two microservice, ```polaris-circuitbreaker-example-a``` and ```polaris-circuitbreaker-example-b```. In these two microservices, ```polaris-circuitbreaker-example-a``` invokes ```polaris-circuitbreaker-example-b```.
This example contains callee-service```polaris-circuitbreaker-callee-service```、```polaris-circuitbreaker-callee-service2```and caller-service```polaris-circuitbreaker-feign-example```、```polaris-circuitbreaker-gateway-example```、```polaris-circuitbreaker-webclient-example```.
## Instruction
@ -21,58 +21,46 @@ spring:
address: ${ip}:${port}
```
###Launching Example
### Launching Example
###Launching Polaris Backend Service
#### Launching Polaris Backend Service
Reference to [Polaris Getting Started](https://github.com/PolarisMesh/polaris#getting-started)
####Launching Application
#### Launching callee service
Note, because verification is needed for circuit-break feature, therefore, one needs to deploy more than two invoked services (two deployment in this example)
Launching```polaris-circuitbreaker-example/polaris-circuitbreaker-callee-service```、```polaris-circuitbreaker-example/polaris-circuitbreaker-callee-service2```
Launching```spring-cloud-tencent-examples/polaris-circuitbreaker-example/polaris-circuitbreaker-example-a```'s ServiceA and ```spring-cloud-tencent-examples/polaris-circuitbreaker-example/polaris-circuitbreaker-example-b```'s ServiceB
note, Service B needs to launch two. One can adjust the port on the same machine.
#### Launching caller service
Two Services B's ```com.tencent.cloud.polaris.circuitbreaker.example.ServiceBController.info``` logics are different. One returns normally, one is abnormal.
##### Launching Feign and Verify
- Maven Package Launching
Launching```polaris-circuitbreaker-example/polaris-circuitbreaker-feign-example```.
Execute under ```spring-cloud-tencent-examples/polaris-discovery-example```
Sending request`curl --location --request GET 'http://127.0.0.1:48080/example/service/a/getBServiceInfo/fallbackFromPolaris'`, Verify circuit breaker and fallback from Polaris-server.
note, Service B needs to launch two. One can adjust the port on the same machine.
Sending request`curl --location --request GET 'http://127.0.0.1:48080/example/service/a/getBServiceInfo/fallbackFromCode'`, Verify circuit breaker and fallback from code.
Two Services B's com.tencent.cloud.polaris.circuitbreaker.example.ServiceBController.info logics are different. One returns normally, one is abnormal.
##### Launching RestTemplate and Verify
```sh
mvn clean package
```
Launching```polaris-circuitbreaker-example/polaris-circuitbreaker-resttemplate-example```.
Then under ``polaris-circuitbreaker-example-a``` and ``polaris-circuitbreaker-example-b``` find the package that generated jar, and run it
Sending request`curl --location --request GET 'http://127.0.0.1:48080/example/service/a/getBServiceInfo/fallbackFromPolaris'`, Verify circuit breaker and fallback from Polaris-server.
```
java -jar ${app.jar}
```
Sending request`curl --location --request GET 'http://127.0.0.1:48080/example/service/a/getBServiceInfo/fallbackFromCode'`, Verify circuit breaker and fallback from code.
Launch application, change ${app.jar} to jar's package name
##### Launching WebClient and Verify
##Verify
Launching```polaris-circuitbreaker-example/polaris-circuitbreaker-webclient-example```。
####Feign Invoke
Sending request`curl --location --request GET 'http://127.0.0.1:48080/example/service/a/getBServiceInfo'`, Verify circuit breaker and fallback from code.
Execute the following orders to invoke Feign, the logic is ```ServiceB``` has an abnormal signal
##### Launching SCG and Verify
```shell
curl -L -X GET 'localhost:48080/example/service/a/getBServiceInfo'
```
Launching```polaris-circuitbreaker-example/polaris-circuitbreaker-gateway-example```。
Expected return condition:
Sending request`curl --location --request GET 'http://127.0.0.1:48080/polaris-circuitbreaker-callee-service/example/service/b/info'`, Verify circuit breaker and fallback from code.
when appear
```
trigger the refuse for service b
```
Changing```polaris-circuitbreaker-example/polaris-circuitbreaker-gateway-example/resources/bootstrap.yml```, delete local fallback and restart, Verify circuit breaker and fallback from Polaris-server.
it means the request signals abnormal ServiceB, and will ciruitbreak this instance, the later requests will return normally.

@ -35,8 +35,8 @@ spring:
'filters[1]':
name: CircuitBreaker
args:
# statusCodes 缺省时会自动识别 "4**,5**" 为错误
# statusCodes: '''4**,502'''
# statusCodes 缺省时会自动识别 "5**" 为错误
# statusCodes: '''404,5**'''
# fallbackUri 缺省时会在熔断触发后拉取 plaris server 配置的降级作为 response
fallbackUri: '''forward:/polaris-fallback'''
# routes:

Loading…
Cancel
Save