Skip to content

Commit e7a8938

Browse files
authored
refactor:polaris examples (#466)
* refactor:polaris examples * examples:finish polaris examples * examples:finish polaris examples * examples:finish polaris examples * examples:finish polaris examples * examples:finish polaris examples * examples:finish polaris examples * examples:finish polaris examples * examples:finish polaris examples * examples:finish polaris examples
1 parent 2a8fb6c commit e7a8938

File tree

28 files changed

+1408
-45
lines changed

28 files changed

+1408
-45
lines changed

go.mod

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
module github.com/apache/dubbo-go-samples
22

33
require (
4-
dubbo.apache.org/dubbo-go/v3 v3.0.3-0.20220730033103-013f0b2804ce
4+
dubbo.apache.org/dubbo-go/v3 v3.0.4-rc1
55
github.com/SkyAPM/go2sky v1.5.0
66
github.com/SkyAPM/go2sky-plugins/dubbo-go v0.0.0-20220718123631-cb8f743b16cf
7-
github.com/apache/dubbo-go-hessian2 v1.11.3
8-
github.com/dubbogo/gost v1.12.6-0.20220719055648-01d5bc07b111
7+
github.com/apache/dubbo-go-hessian2 v1.11.4
8+
github.com/dubbogo/gost v1.13.2
99
github.com/dubbogo/grpc-go v1.42.10
10-
github.com/dubbogo/triple v1.1.9
10+
github.com/dubbogo/triple v1.2.2-rc2
1111
github.com/golang/protobuf v1.5.2
1212
github.com/opentracing/opentracing-go v1.2.0
1313
github.com/openzipkin-contrib/zipkin-go-opentracing v0.4.5
1414
github.com/openzipkin/zipkin-go v0.2.2
1515
github.com/pkg/errors v0.9.1
1616
github.com/seata/seata-go v0.1.0-rc1
1717
github.com/stretchr/testify v1.8.1
18-
github.com/uber/jaeger-client-go v2.29.1+incompatible
18+
github.com/uber/jaeger-client-go v2.30.0+incompatible
1919
go.opentelemetry.io/otel v1.11.0
2020
go.opentelemetry.io/otel/exporters/jaeger v1.10.0
2121
go.opentelemetry.io/otel/sdk v1.10.0

go.sum

Lines changed: 86 additions & 36 deletions
Large diffs are not rendered by default.

polaris/limit/README-zh.md

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
# Dubbo Go & Polaris TpsLimiter Example
2+
3+
[English](./README.md) | 中文
4+
5+
## 使用服务限流功能
6+
7+
在 dubbogo 中快速体验北极星的服务限流能力
8+
9+
## 北极星服务端安装
10+
11+
[北极星服务端单机版本安装文档](https://polarismesh.cn/docs/%E4%BD%BF%E7%94%A8%E6%8C%87%E5%8D%97/%E6%9C%8D%E5%8A%A1%E7%AB%AF%E5%AE%89%E8%A3%85/%E5%8D%95%E6%9C%BA%E7%89%88%E5%AE%89%E8%A3%85/)
12+
13+
[北极星服务端集群版本安装文档](https://polarismesh.cn/docs/%E4%BD%BF%E7%94%A8%E6%8C%87%E5%8D%97/%E6%9C%8D%E5%8A%A1%E7%AB%AF%E5%AE%89%E8%A3%85/%E9%9B%86%E7%BE%A4%E7%89%88%E5%AE%89%E8%A3%85/)
14+
15+
## 如何使用
16+
17+
[北极星服务限流使用文档](https://polarismesh.cn/docs/%E5%8C%97%E6%9E%81%E6%98%9F%E6%98%AF%E4%BB%80%E4%B9%88/%E5%8A%9F%E8%83%BD%E7%89%B9%E6%80%A7/%E6%B5%81%E9%87%8F%E7%AE%A1%E7%90%86/#%E8%AE%BF%E9%97%AE%E9%99%90%E6%B5%81)
18+
19+
### dubbogo.yaml 配置文件
20+
21+
在使用 PolarisMesh 的服务限流能力时,需要先启用 PolarisMesh 在 dubbogo 中的注册发现功能。
22+
23+
```yaml
24+
dubbo:
25+
registries:
26+
polarisMesh:
27+
protocol: polaris
28+
address: ${北极星服务端IP}:8091
29+
namespace: ${北极星命名空间信息}
30+
token: ${北极星资源鉴权 token} # 如果北极星服务端开启了针对客户端的鉴权,则需要配置该参数
31+
provider:
32+
services:
33+
UserProvider:
34+
interface: org.apache.dubbo.UserProvider.Test
35+
tps.limiter: polaris-limit # 配置 tps.limiter 为 polaris-limiter 即可
36+
37+
```
38+
39+
注意:PolarisMesh 的服务限流能力是工作在 Provider 侧的。
40+
41+
### 如何配置服务限流参数
42+
43+
dubbogo 中的 PolarisMesh TpsLimiter 扩展点实现,能够根据用户配置的限流规则,自动的从当前 RPC 调用上下文以及请求信息中识别出需要参与限流的请求标签信息
44+
45+
![](./images/dubbogo-ratelimit-rule.png)
46+
47+
- 请求匹配规则为 **请求参数(QUERY)**
48+
- 标签来源: RPC 调用中方法的入参,即 Invoaction.Arguments()
49+
- 标签键规则
50+
- 方法仅有一个入参: param.$.${fieldName}, **param.** 为固定前缀,后面的表达式为标准的 JSONPath expressions,[参考文档](https://goessner.net/articles/JsonPath/)
51+
- 方法有多个参数: param[${index}].$.${fieldName}, **param[${index}].** 为固定前缀,${index} 代表是方法入参中的第几个参数,下标起始位置从 0 开始;后面的表达式为标准的 JSONPath expressions,[参考文档](https://goessner.net/articles/JsonPath/)
52+
- 请求匹配规则为 **请求头(HEADER)**:
53+
- 标签来源: RPC 调用的额外标签信息,即 Invoaction.Attachments()
54+
55+
### 运行服务提供者
56+
57+
进入 go-server 的 cmd 目录,执行以下命令
58+
59+
```
60+
export DUBBO_GO_CONFIG_PATH="../conf/dubbogo.yaml"
61+
go run .
62+
```
63+
64+
当看到以下日志时即表示 server 端启动成功
65+
66+
```log
67+
INFO dubbo/dubbo_protocol.go:84 [DUBBO Protocol] Export service:
68+
```
69+
70+
71+
### 运行服务调用者
72+
73+
进入 go-client 的 cmd 目录,执行以下命令
74+
75+
76+
```
77+
export DUBBO_GO_CONFIG_PATH="../conf/dubbogo.yml"
78+
go run .
79+
```
80+
81+
当看到以下日志时即表示 go-client 成功发现 go-server 并发起了 RPC 调用
82+
83+
```log
84+
INFO cmd/main.go:75 response: &{A001 Alex Stocks 18 2022-11-19 12:52:38.092 +0800 CST}
85+
```
86+
87+
当看到以下日志时即表示在 PolarisMesh 针对 go-server 配置的限流策略已生效
88+
89+
```log
90+
ERROR handler/rejected_execution_handler_only_log.go:73 The invocation was rejected
91+
```

polaris/limit/README.md

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
# Dubbo Go & Polaris TpsLimiter Example
2+
3+
English | [中文](./README-zh.md)
4+
5+
## Use the service current limit function
6+
7+
Quickly experience Polaris' service current limiting capabilities in dubbogo
8+
9+
## Polaris server installation
10+
11+
[Polaris Server Standalone Version Installation Documentation](https://polarismesh.cn/docs/%E4%BD%BF%E7%94%A8%E6%8C%87%E5%8D%97/%E6%9C%8D%E5%8A%A1%E7%AB%AF%E5%AE%89%E8%A3%85/%E5%8D%95%E6%9C%BA%E7%89%88%E5%AE%89%E8%A3%85/)
12+
13+
[Polaris Server Cluster Version Installation Documentation](https://polarismesh.cn/docs/%E4%BD%BF%E7%94%A8%E6%8C%87%E5%8D%97/%E6%9C%8D%E5%8A%A1%E7%AB%AF%E5%AE%89%E8%A3%85/%E9%9B%86%E7%BE%A4%E7%89%88%E5%AE%89%E8%A3%85/)
14+
15+
## how to use
16+
17+
[Polaris Service Current Limitation Documentation](https://polarismesh.cn/docs/%E5%8C%97%E6%9E%81%E6%98%9F%E6%98%AF%E4%BB%80%E4%B9%88/%E5%8A%9F%E8%83%BD%E7%89%B9%E6%80%A7/%E6%B5%81%E9%87%8F%E7%AE%A1%E7%90%86/#%E8%AE%BF%E9%97%AE%E9%99%90%E6%B5%81)
18+
19+
### dubbogo.yaml configuration file
20+
21+
When using PolarisMesh's service current limiting capability, you need to enable PolarisMesh's registration discovery function in dubbogo firstly.
22+
23+
````yaml
24+
dubbo:
25+
registries:
26+
polarisMesh:
27+
protocol: polaris
28+
address: ${Polaris server IP}:8091
29+
namespace: ${Polaris namespace information}
30+
token: ${Polaris resource authentication token} # If the Polaris server has enabled authentication for the client, you need to configure this parameter
31+
provider:
32+
services:
33+
UserProvider:
34+
interface: org.apache.dubbo.UserProvider.Test
35+
tps.limiter: polaris-limit # Configure tps.limiter as polaris-limiter
36+
37+
````
38+
39+
Note: The service current limiting capability of PolarisMesh works on the Provider side.
40+
41+
### How to configure service current limit parameters
42+
43+
The implementation of the PolarisMesh TpsLimiter extension point in dubbogo can automatically identify the request tag information that needs to participate in current limiting from the current RPC call context and request information according to the current limiting rules configured by the user.
44+
45+
![](./images/dubbogo-ratelimit-rule.png)
46+
47+
- The request matching rule is **Request parameter(QUERY)**
48+
- Tag source: the input parameter of the method in the RPC call, namely Invoaction.Arguments()
49+
- Tag key rules
50+
- The method has only one input parameter: param.$.${fieldName}, **param.** is a fixed prefix, the following expressions are standard JSONPath expressions, [reference document](https://goessner.net/ articles/JsonPath/)
51+
- The method has multiple parameters: param[${index}].$.${fieldName}, **param[${index}].** is a fixed prefix, ${index} represents the first parameter in the method parameter Several parameters, the starting position of the subscript starts from 0; the following expressions are standard JSONPath expressions, [reference document](https://goessner.net/articles/JsonPath/)
52+
- The request matching rule is **request header (HEADER)**:
53+
- Tag source: Additional tag information for RPC calls, i.e. Invoaction.Attachments()
54+
55+
### Running the service provider
56+
57+
Enter the cmd directory of go-server and execute the following command
58+
59+
````
60+
export DUBBO_GO_CONFIG_PATH="../conf/dubbogo.yml"
61+
go run .
62+
````
63+
64+
When you see the following log, it means that the server side started successfully
65+
66+
````log
67+
INFO dubbo/dubbo_protocol.go:84 [DUBBO Protocol] Export service:
68+
````
69+
70+
71+
### Run the service caller
72+
73+
Enter the cmd directory of go-client and execute the following command
74+
75+
76+
````
77+
export DUBBO_GO_CONFIG_PATH="../conf/dubbogo.yml"
78+
go run .
79+
````
80+
81+
When you see the following log, it means that go-client successfully discovered go-server and made an RPC call
82+
83+
````log
84+
INFO cmd/main.go:75 response: &{A001 Alex Stocks 18 2022-11-19 12:52:38.092 +0800 CST}
85+
````
86+
87+
When you see the following log, it means that the current limiting policy configured for go-server in PolarisMesh has taken effect
88+
89+
````log
90+
ERROR handler/rejected_execution_handler_only_log.go:73 The invocation was rejected
91+
````
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package main
19+
20+
import (
21+
"context"
22+
"errors"
23+
"time"
24+
)
25+
26+
import (
27+
"dubbo.apache.org/dubbo-go/v3/config"
28+
_ "dubbo.apache.org/dubbo-go/v3/imports"
29+
30+
hessian "github.com/apache/dubbo-go-hessian2"
31+
32+
"github.com/dubbogo/gost/log/logger"
33+
)
34+
35+
type UserProviderWithCustomGroupAndVersion struct {
36+
GetUser func(ctx context.Context, req *User) (rsp *User, err error)
37+
}
38+
39+
type UserProvider struct {
40+
GetUser func(ctx context.Context, req *User) (rsp *User, err error)
41+
}
42+
43+
type User struct {
44+
ID string
45+
Name string
46+
Age int32
47+
Time time.Time
48+
}
49+
50+
func (u *User) JavaClassName() string {
51+
return "org.apache.dubbo.User"
52+
}
53+
54+
func main() {
55+
var userProvider = &UserProvider{}
56+
var userProviderWithCustomRegistryGroupAndVersion = &UserProviderWithCustomGroupAndVersion{}
57+
config.SetConsumerService(userProvider)
58+
config.SetConsumerService(userProviderWithCustomRegistryGroupAndVersion)
59+
hessian.RegisterPOJO(&User{})
60+
err := config.Load()
61+
if err != nil {
62+
panic(err)
63+
}
64+
65+
logger.Infof("\n\n\nstart to test dubbo")
66+
67+
var successCount, failCount int64
68+
for i := 0; i < 10; i++ {
69+
time.Sleep(50 * time.Millisecond)
70+
user, err := userProvider.GetUser(context.TODO(), &User{Name: "Alex03"})
71+
if err != nil {
72+
failCount++
73+
logger.Infof("error: %v\n", err)
74+
} else {
75+
successCount++
76+
}
77+
logger.Infof("response: %v\n", user)
78+
}
79+
logger.Infof("successCount=%v, failCount=%v\n", successCount, failCount)
80+
81+
if failCount == 0 {
82+
panic(errors.New("need failCount > 0"))
83+
}
84+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
dubbo:
2+
application:
3+
name: myApp # metadata: application=myApp; name=myApp
4+
module: opensource #metadata: module=opensource
5+
group: myAppGroup # no metadata record
6+
organization: dubbo # metadata: organization=dubbo
7+
owner: laurence # metadata: owner=laurence
8+
version: myversion # metadata: app.version=myversion
9+
environment: pro # metadata: environment=pro
10+
registries:
11+
polarisMesh:
12+
protocol: polaris
13+
address: 183.47.111.80:8091
14+
namespace: dubbogo
15+
consumer:
16+
references:
17+
UserProvider:
18+
protocol: dubbo
19+
interface: org.apache.dubbo.UserProvider.Test
20+
UserProviderWithCustomGroupAndVersion:
21+
protocol: dubbo
22+
interface: org.apache.dubbo.UserProvider.Test2
23+
version: myInterfaceVersion # dubbo interface version must be same with server

0 commit comments

Comments
 (0)