You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
spring-cloud-tencent/spring-cloud-tencent-examples/polaris-circuitbreaker-example/README-zh.md

73 lines
2.1 KiB

# Spring Cloud Polaris CircuitBreaker Example
## 样例简介
本样例将介绍如何在Spring Cloud项目中使用```spring-cloud-starter-tencent-polaris-circuitbreaker```以使用其各项功能。
2 years ago
该样例分为两个微服务,即
1. ```polaris-circuitbreaker-example-a```
2. ```polaris-circuitbreaker-example-b``` 有两个实例 B默认正常服务和 B2模拟异常服务
``` polaris-circuitbreaker-example-a``` 对 ```polaris-circuitbreaker-example-b```发生调用。
## 使用说明
### 修改配置
2 years ago
修改 resource/bootstrap.yml 中北极星的服务端地址
```yaml
spring:
cloud:
polaris:
2 years ago
address: grpc://${ip}:8091
```
### 启动样例
#### 启动Polaris后端服务
3 years ago
参考[Polaris Getting Started](https://github.com/PolarisMesh/polaris#getting-started)。
2 years ago
### 启动应用
- IDEA启动
2 years ago
分别启动
2 years ago
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```
2 years ago
## 验证
2 years ago
### Feign调用
执行以下命令发起Feign调用其逻辑为```ServiceB```抛出一个异常
```shell
curl -L -X GET 'localhost:48080/example/service/a/getBServiceInfo'
```
预期返回情况:
在出现
```
2 years ago
hello world ! I'm a service B1
```
时,表示 B2 已经被熔断了,请求只会打到 B1。
### 验证更多场景
您也可以调整 ```example-b``` 和 ```example-b2``` 中 ```resource/bootstrap.yml``` is-throw-runtime-exception
参数调整服务是否抛出异常。
例如测试以下场景:
1. 两个实例都是正常的,这时候预期是 B1 和 B2 都能正常被调用到
2. 一个实例正常一个实例不正常,这时候预期是不正常实例被熔断,请求只会打到正常的实例
3. 两个实例都不正常,这时候 Feign 会自动 Fallback 到 ProviderBFallback.java 的实现类