Skip to content

Commit

Permalink
render server and client data id individually
Browse files Browse the repository at this point in the history
  • Loading branch information
whalecold committed Sep 18, 2023
1 parent 64a829d commit 70312f9
Show file tree
Hide file tree
Showing 10 changed files with 96 additions and 203 deletions.
17 changes: 9 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func main() {

### Nacos Configuration

The client is initialized according to the parameters of `Options` and connects to the nacos server. If the parameters are empty, the addr, port and namespace of nacos are obtained from the environment variables. After the connection is established, the suite subscribes the appropriate configuration based on `configGroup` and `configDataId` to updates its own policy dynamically. See the environment variables below for specific parameters.
The client is initialized according to the parameters of `Options` and connects to the nacos server. After the connection is established, the suite subscribes the appropriate configuration based on `Group`, `ServerDataIDFormat` and `ClientDataIDFormat` to updates its own policy dynamically. See the environment variables below for specific parameters.

The configuration format supports `json` and `yaml`. You can use the [SetParser](https://github.com/kitex-contrib/config-nacos/blob/eb006978517678dd75a81513142d3faed6a66f8d/nacos/nacos.go#L68) function to customise the format parsing method, and the `CustomFunction` function to customise the format of the subscription function during `NewSuite`.
####
Expand All @@ -120,15 +120,16 @@ The configuration format supports `json` and `yaml`. You can use the [SetParser]

Provide the mechanism to custom the nacos parameter `vo.ConfigParam`.

#### Environment Variable
#### Options Variable

| Environment Variable Name | Environment Variable Default Value | Environment Variable Introduction |
| Variable Name | Default Value | Introduction |
| ------------------------- | ---------------------------------- | --------------------------------- |
| KITEX_CONFIG_NACOS_SERVER_ADDR | 127.0.0.1 | Nacos server address |
| KITEX_CONFIG_NACOS_SERVER_PORT | 8848 | Nacos server port |
| KITEX_CONFIG_NACOS_NAMESPACE | | The namespaceId of nacos |
| KITEX_CONFIG_NACOS_DATA_ID | {{.ClientServiceName}}.{{.ServerServiceName}}.{{.Category}} | Use go [template](https://pkg.go.dev/text/template) syntax rendering to generate the appropriate ID, and use `ClientServiceName` `ServiceName` `Category` three metadata that can be customised |
| KITEX_CONFIG_NACOS_GROUP | DEFAULT_GROUP | Use fixed values or dynamic rendering. Usage is the same as configDataId. |
| Address | 127.0.0.1 | Nacos server address |
| Port | 8848 | Nacos server port |
| NamespaceID | | The namespaceID of Nacos 中的 namespace Id |
| ClientDataIDFormat | {{.ClientServiceName}}.{{.ServerServiceName}}.{{.Category}} | Use go [template](https://pkg.go.dev/text/template) syntax rendering to generate the appropriate ID, and use `ClientServiceName` `ServiceName` `Category` three metadata that can be customised |
| ServerDataIDFormat | {{.ServerServiceName}}.{{.Category}} | Use go [template](https://pkg.go.dev/text/template) syntax rendering to generate the appropriate ID, and use `ServiceName` `Category` two metadatas that can be customised |
| Group | DEFAULT_GROUP | Use fixed values or dynamic rendering. Usage is the same as configDataId. |

#### Governance Policy
> The configDataId and configGroup in the following example use default values, the service name is `ServiceName` and the client name is `ClientName`.
Expand Down
20 changes: 10 additions & 10 deletions README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,24 +110,24 @@ func main() {
```
### Nacos 配置

根据 Options 的参数初始化 client, 如果参数为空则会根据环境变量获取到 nacos 的 addr, port 以及 namespace 链接到 nacos 服务器上,建立链接之后 suite 会根据 configGroup 以及 configDataId 订阅对应的配置并动态更新自身策略,具体参数参考下面环境变量。
根据 Options 的参数初始化 client,建立链接之后 suite 会根据 `Group` 以及 `ServerDataIDFormat` 或者 `ClientDataIDFormat` 订阅对应的配置并动态更新自身策略,具体参数参考下面环境变量。

配置的格式默认支持 `json``yaml`,可以使用函数 `SetParser` 进行自定义格式解析方式,并在 `NewSuite` 的时候使用 `CustomFunction` 函数修改订阅函数的格式。
配置的格式默认支持 `json``yaml`,可以使用函数 [SetParser](https://github.com/kitex-contrib/config-nacos/blob/eb006978517678dd75a81513142d3faed6a66f8d/nacos/nacos.go#L68) 进行自定义格式解析方式,并在 `NewSuite` 的时候使用 `CustomFunction` 函数修改订阅函数的格式。

#### CustomFunction

允许用户自定义 nacos 的参数.

#### 环境变量
#### Options 默认值


| 变量名 | 变量默认值 | 作用 |
| 参数 | 变量默认值 | 作用 |
| ------------------------- | ---------------------------------- | --------------------------------- |
| KITEX_CONFIG_NACOS_SERVER_ADDR | 127.0.0.1 | nacos 服务器地址 |
| KITEX_CONFIG_NACOS_SERVER_PORT | 8848 | nacos 服务器端口 |
| KITEX_CONFIG_NACOS_NAMESPACE | | nacos 中的 namespace Id |
| KITEX_CONFIG_NACOS_DATA_ID | {{.ClientServiceName}}.{{.ServerServiceName}}.{{.Category}} | 使用 go [template](https://pkg.go.dev/text/template) 语法渲染生成对应的 ID, 使用 `ClientServiceName` `ServiceName` `Category` 三个元数据,可以自定义 |
| KITEX_CONFIG_NACOS_GROUP | DEFAULT_GROUP | 使用固定值,也可以动态渲染,用法同 configDataId |
| Address | 127.0.0.1 | nacos 服务器地址 |
| Port | 8848 | nacos 服务器端口 |
| NamespaceID | | nacos 中的 namespace Id |
| ClientDataIDFormat | {{.ClientServiceName}}.{{.ServerServiceName}}.{{.Category}} | 使用 go [template](https://pkg.go.dev/text/template) 语法渲染生成对应的 ID, 使用 `ClientServiceName` `ServiceName` `Category` 三个元数据 |
| ServerDataIDFormat | {{.ServerServiceName}}.{{.Category}} | 使用 go [template](https://pkg.go.dev/text/template) 语法渲染生成对应的 ID, 使用 `ServiceName` `Category` 两个元数据 |
| Group | DEFAULT_GROUP | 使用固定值,也可以动态渲染,用法同 DataIDFormat |

#### 治理策略

Expand Down
2 changes: 1 addition & 1 deletion client/circuit_breaker.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (
func WithCircuitBreaker(dest, src string, nacosClient nacos.Client,
cfs ...nacos.CustomFunction,
) []client.Option {
param, err := nacosClient.NacosConfigParam(&nacos.ConfigParamConfig{
param, err := nacosClient.ClientConfigParam(&nacos.ConfigParamConfig{
Category: circuitBreakerConfigName,
ServerServiceName: dest,
ClientServiceName: src,
Expand Down
2 changes: 1 addition & 1 deletion client/retry.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
func WithRetryPolicy(dest, src string, nacosClient nacos.Client,
cfs ...nacos.CustomFunction,
) []client.Option {
param, err := nacosClient.NacosConfigParam(&nacos.ConfigParamConfig{
param, err := nacosClient.ClientConfigParam(&nacos.ConfigParamConfig{
Category: retryConfigName,
ServerServiceName: dest,
ClientServiceName: src,
Expand Down
2 changes: 1 addition & 1 deletion client/rpc_timeout.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
func WithRPCTimeout(dest, src string, nacosClient nacos.Client,
cfs ...nacos.CustomFunction,
) []client.Option {
param, err := nacosClient.NacosConfigParam(&nacos.ConfigParamConfig{
param, err := nacosClient.ClientConfigParam(&nacos.ConfigParamConfig{
Category: rpcTimeoutConfigName,
ServerServiceName: dest,
ClientServiceName: src,
Expand Down
97 changes: 0 additions & 97 deletions nacos/env.go

This file was deleted.

38 changes: 0 additions & 38 deletions nacos/env_test.go

This file was deleted.

Loading

0 comments on commit 70312f9

Please sign in to comment.