-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: haozhicui <[email protected]>
- Loading branch information
haozhicui
committed
Dec 12, 2024
1 parent
689d173
commit 37f1ada
Showing
10 changed files
with
2,603 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
# Polaris Go | ||
|
||
[English](./README.md) | 中文 | ||
|
||
## 使用负载均衡功能 | ||
|
||
快速体验北极星的负载均衡能力 | ||
|
||
## 如何使用 | ||
|
||
### 构建可执行文件 | ||
|
||
构建 provider | ||
|
||
``` | ||
# linux/mac | ||
cd ./provider | ||
go build -o provider | ||
# windows | ||
cd ./provider | ||
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打开控制台 | ||
|
||
### 修改配置 | ||
|
||
指定北极星服务端地址,需编辑polaris.yaml文件,填入服务端地址 | ||
|
||
指定负载均衡策略配置 | ||
|
||
``` | ||
global: | ||
serverConnector: | ||
addresses: | ||
- 127.0.0.1:8091 | ||
consumer: | ||
loadbalancer: | ||
type: weightedRandom | ||
``` | ||
|
||
### 执行程序 | ||
|
||
运行构建出的**provider**可执行文件 | ||
|
||
在不同的节点运行多个provider,或通过--port参数指定不同端口, 在同一个节点运行多个provider | ||
|
||
``` | ||
# linux/mac运行命令 | ||
./provider | ||
# windows运行命令 | ||
./provider.exe | ||
``` | ||
|
||
运行构建出的**consumer**可执行文件 | ||
|
||
``` | ||
# linux/mac运行命令 | ||
./consumer | ||
# windows运行命令 | ||
./consumer.exe | ||
``` | ||
|
||
|
||
### 验证 | ||
请求被负载均衡到各个provider | ||
|
||
``` | ||
curl http://127.0.0.1:18080/echo | ||
Hello, I'm LoadBalanceEchoServer Provider, My host : 10.10.0.10:32451 | ||
curl http://127.0.0.1:18080/echo | ||
Hello, I'm LoadBalanceEchoServer Provider, My host : 10.10.0.11:31102 | ||
curl http://127.0.0.1:18080/echo | ||
Hello, I'm LoadBalanceEchoServer Provider, My host : 10.10.0.10:32451 | ||
curl http://127.0.0.1:18080/echo | ||
Hello, I'm LoadBalanceEchoServer Provider, My host : 10.10.0.10:32451 | ||
curl http://127.0.0.1:18080/echo | ||
Hello, I'm LoadBalanceEchoServer Provider, My host : 10.10.0.11:31102 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
# Polaris Go | ||
|
||
English | [中文](./README-zh.md) | ||
|
||
## Using Load Balancing Feature | ||
|
||
Experience the load balancing capability of Polaris quickly. | ||
|
||
## How to use | ||
|
||
### Build an executable | ||
|
||
Build provider | ||
|
||
``` | ||
# linux/mac | ||
cd ./provider | ||
go build -o provider | ||
# windows | ||
cd ./provider | ||
go build -o provider.exe | ||
``` | ||
|
||
Build consumer | ||
|
||
``` | ||
# linux/mac | ||
cd ./consumer | ||
go build -o consumer | ||
# windows | ||
cd ./consumer | ||
go build -o consumer.exe | ||
``` | ||
|
||
### Accessing the 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 | ||
|
||
### Modifying Configuration | ||
|
||
Specify the Polaris server address by editing the polaris.yaml file and filling in the server address. | ||
|
||
Specify the load balancing strategy configuration: | ||
|
||
``` | ||
global: | ||
serverConnector: | ||
addresses: | ||
- 127.0.0.1:8091 | ||
consumer: | ||
loadbalancer: | ||
type: weightedRandom | ||
``` | ||
|
||
### Execute program | ||
|
||
Run the built **provider** executable | ||
|
||
Run multiple providers on different nodes or specify different ports using the --port parameter. Run multiple providers on the same node. | ||
|
||
``` | ||
# linux/mac | ||
./provider | ||
# windows | ||
./provider.exe | ||
``` | ||
|
||
Run the built **consumer** executable | ||
|
||
``` | ||
# linux/mac | ||
./consumer | ||
# windows | ||
./consumer.exe | ||
``` | ||
|
||
|
||
### Verify | ||
|
||
Requests will be load balanced to different providers. | ||
|
||
``` | ||
curl http://127.0.0.1:18080/echo | ||
Hello, I'm LoadBalanceEchoServer Provider, My host : 10.10.0.10:32451 | ||
curl http://127.0.0.1:18080/echo | ||
Hello, I'm LoadBalanceEchoServer Provider, My host : 10.10.0.11:31102 | ||
curl http://127.0.0.1:18080/echo | ||
Hello, I'm LoadBalanceEchoServer Provider, My host : 10.10.0.10:32451 | ||
curl http://127.0.0.1:18080/echo | ||
Hello, I'm LoadBalanceEchoServer Provider, My host : 10.10.0.10:32451 | ||
curl http://127.0.0.1:18080/echo | ||
Hello, I'm LoadBalanceEchoServer Provider, My host : 10.10.0.11:31102 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
module github.com/polarismesh/polaris-go-loadbalancer-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 => ../../../ |
Oops, something went wrong.