Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add circuitbreak service example #222

Merged
merged 1 commit into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 99 additions & 0 deletions examples/circuitbreaker/service/README-zh.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
# Polaris Go

[English](./README.md) | 中文

## 使用实例故障熔断

北极星支持及时熔断异常的服务、接口、实例或者实例分组,降低请求失败率。
## 如何使用

### 构建可执行文件

构建 provider

```
# linux/mac
cd ./provider
go build -o provider

# windows
cd ./consumer
go build -o provider.exe
```

构建 consumer

```
# linux/mac
cd ./consumer
go build -o consumer

# windows
cd ./consumer
go build -o consumer.exe
```
### 进入控制台

预先通过北极星控制台创建对应的服务,如果是通过本地一键安装包的方式安装,直接在浏览器通过127.0.0.1:8080打开控制台

### 设置熔断规则

![create_circuitbreaker](./image/create_circuitbreaker.png)

### 修改配置

指定北极星服务端地址,需编辑polaris.yaml文件,填入服务端地址

```
global:
serverConnector:
addresses:
- 127.0.0.1:8091
```

### 执行程序

### 执行程序

运行构建出的**provider**可执行文件

```
# linux/mac运行命令
./provider

# windows运行命令
./provider.exe
```

运行构建出的**consumer**可执行文件

```
# linux/mac运行命令
./provider

# windows运行命令
./provider.exe
```

### 验证

快速的发起多次**curl**请求命令

```
-- 第一次发起请求
curl -H 'user-id: polaris' http://127.0.0.1:18080/echo

Hello, My host : 127.0.0.1:8888
Hello, My host : 127.0.0.1:9999
...
Hello, My host : 127.0.0.1:9999

-- 关闭某些provider,在发起请求

"Hello, My host : %s:%d", svr.host, svr.port
dial tcp 127.0.0.1:37907: connect: connection refused

<多次调用触发熔断>

it's fallback
...
97 changes: 97 additions & 0 deletions examples/circuitbreaker/service/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
# Polaris Go

English | [中文](./README-zh.md)

## Use troubleshooting

Polaris supports timely fuse from abnormal services, interfaces, examples, or instance packets, and reduce the request failure rate.
## How to use

### Build an executable

Build provider

```
# linux/mac
cd ./provider
go build -o provider

# windows
cd ./consumer
go build -o provider.exe
```

Build consumer

```
# linux/mac
cd ./consumer
go build -o consumer

# windows
cd ./consumer
go build -o consumer.exe
```
### Enter console

Create a corresponding service through the Arctic Star Console, if you are installed by a local one-click installation package, open the console directly on the browser through 127.0.0.1:8080

### Set fuck rule

![create_circuitbreaker](./image/create_circuitbreaker.png)

### Change setting

Specify the Arctic Star server address, you need to edit the Polaris.yaml file, fill in the server address.

```
global:
serverConnector:
addresses:
- 127.0.0.1:8091
```

### Execute program

Run the built **provider** executable

```
# linux/mac
./provider

# windows
./provider.exe
```

Run the built-in **consumer** executable

```
# linux/mac
./provider

# windows
./provider.exe
```

### Verify

Quick initiatures multiple times **curl** request command

```
-- First initiative
curl -H 'user-id: polaris' http://127.0.0.1:18080/echo

Hello, My host : 127.0.0.1:8888
Hello, My host : 127.0.0.1:9999
...
Hello, My host : 127.0.0.1:9999

-- Close any provider,request again

"Hello, My host : %s:%d", svr.host, svr.port
dial tcp 127.0.0.1:37907: connect: connection refused

<trigger the cirtcuitbreaker>

it's fallback
...
38 changes: 38 additions & 0 deletions examples/circuitbreaker/service/consumer/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
module github.com/polarismesh/polaris-go-circuitbreaker-consumer

go 1.17

require github.com/polarismesh/polaris-go v1.5.5

require (
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/dlclark/regexp2 v1.7.0 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/natefinch/lumberjack v2.0.0+incompatible // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/polarismesh/specification v1.4.1 // indirect
github.com/prometheus/client_golang v1.12.2 // indirect
github.com/prometheus/client_model v0.2.0 // indirect
github.com/prometheus/common v0.32.1 // indirect
github.com/prometheus/procfs v0.7.3 // indirect
github.com/spaolacci/murmur3 v1.1.0 // indirect
go.uber.org/atomic v1.10.0 // indirect
go.uber.org/multierr v1.8.0 // indirect
go.uber.org/zap v1.21.0 // indirect
golang.org/x/net v0.2.0 // indirect
golang.org/x/sys v0.2.0 // indirect
golang.org/x/text v0.4.0 // indirect
google.golang.org/genproto v0.0.0-20221014213838-99cd37c6964a // indirect
google.golang.org/grpc v1.51.0 // indirect
google.golang.org/protobuf v1.28.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
)

replace github.com/polarismesh/polaris-go => ../../../../
Loading
Loading