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

79 lines
2.4 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

# Spring Cloud Polaris CircuitBreaker Example
## 样例简介
本样例将介绍如何在Spring Cloud项目中使用```spring-cloud-starter-tencent-polaris-circuitbreaker```以使用其各项功能。
该样例分为两个微服务即polaris-circuitbreaker-example-a和polaris-circuitbreaker-example-b。其中polaris-circuitbreaker-example-a对polaris-circuitbreaker-example-b发生调用。
## 使用说明
### 修改配置
配置如下所示。其中,${ip}和${port}为Polaris后端服务的IP地址与端口号。
```yaml
spring:
application:
name: ${application.name}
cloud:
polaris:
address: ${ip}:${port}
```
### 启动样例
#### 启动Polaris后端服务
参考[Polaris Getting Started](https://github.com/PolarisMesh/polaris#getting-started)。
#### 启动应用
注意,由于需要验证熔断功能,因此需要部署两个及以上的被调服务(样例中部署两个即可)。
- IDEA启动
分别启动```spring-cloud-tencent-examples/polaris-circuitbreaker-example/polaris-circuitbreaker-example-a```下的```ServiceA```和```spring-cloud-tencent-examples/polaris-circuitbreaker-example/polaris-circuitbreaker-example-b```下的```ServiceB```。
注意ServiceB需要启动两个。同机器上可以修改端口号来实现。
两个ServiceB的com.tencent.cloud.polaris.circuitbreaker.example.ServiceBController.info的逻辑需不同即一个正常返回一个抛出异常。
- Maven打包启动
在```spring-cloud-tencent-examples/polaris-discovery-example```下执行
注意ServiceB需要启动两个。同机器上可以修改端口号来实现。
两个ServiceB的com.tencent.cloud.polaris.circuitbreaker.example.ServiceBController.info的逻辑需不同即一个正常返回一个抛出异常。
```sh
mvn clean package
```
然后在```polaris-circuitbreaker-example-a```和```polaris-circuitbreaker-example-b```下找到生成的jar包运行
```
java -jar ${app.jar}
```
启动应用,其中${app.jar}替换为对应的jar包名。
### 验证
#### Feign调用
执行以下命令发起Feign调用其逻辑为```ServiceB```抛出一个异常
```shell
curl -L -X GET 'localhost:48080/example/service/a/getBServiceInfo'
```
预期返回情况:
在出现
```
trigger the refuse for service b
```
表示请求到有异常的ServiceB需要熔断这个实例。后面的所有请求都会得到正常返回。