docs(readme): 为所有客户端SDK添加英文版README及语言切换链接
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
# Kenaito Config Center .NET Client
|
||||
|
||||
[English](README_EN.md) | 中文
|
||||
|
||||
kenaito-conf 配置中心的 .NET 客户端 SDK。
|
||||
|
||||
## 安装
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
# Kenaito Config Center .NET Client
|
||||
|
||||
.NET client SDK for the Kenaito Config Center.
|
||||
|
||||
## Installation
|
||||
|
||||
### Local Build
|
||||
|
||||
```bash
|
||||
cd kenaito-conf-dotnet-client
|
||||
dotnet build
|
||||
```
|
||||
|
||||
### As Local Dependency
|
||||
|
||||
Reference in the demo project's csproj:
|
||||
|
||||
```xml
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="../kenaito-conf-dotnet-client/KenaitoConfClient.csproj" />
|
||||
</ItemGroup>
|
||||
```
|
||||
|
||||
## Quick Start
|
||||
|
||||
```csharp
|
||||
using Kenaito.Conf.Client;
|
||||
|
||||
var config = new Config
|
||||
{
|
||||
BaseUrl = "http://localhost:8080",
|
||||
AppName = "kenaito-dotnet-demo",
|
||||
Env = "daily",
|
||||
SyncInterval = 10
|
||||
};
|
||||
|
||||
var client = new Client(config);
|
||||
|
||||
client.OnChange(changed =>
|
||||
{
|
||||
Console.WriteLine("Config changed:");
|
||||
foreach (var kv in changed)
|
||||
{
|
||||
Console.WriteLine($" {kv.Key} = {kv.Value}");
|
||||
}
|
||||
});
|
||||
|
||||
await client.StartAsync();
|
||||
|
||||
var dbHost = client.Get("database.host");
|
||||
Console.WriteLine($"database.host = {dbHost}");
|
||||
|
||||
Console.ReadLine();
|
||||
client.Stop();
|
||||
```
|
||||
|
||||
## Configuration
|
||||
|
||||
| Parameter | Description | Default | Required |
|
||||
|-----------|-------------|---------|----------|
|
||||
| BaseUrl | Config center URL | - | Yes |
|
||||
| AppName | Application name | - | Yes |
|
||||
| Env | Environment | dev | No |
|
||||
| Version | Config version | latest | No |
|
||||
| Token | Auth token | null | No |
|
||||
| SyncInterval | Sync interval (seconds) | 10 | No |
|
||||
| CacheDir | Cache directory | . | No |
|
||||
| IgnoreGlobal | Whether to ignore global configs | false | No |
|
||||
|
||||
## Features
|
||||
|
||||
- Fetch all configs on startup
|
||||
- Periodic incremental config sync
|
||||
- Local file cache, load from cache when service is unavailable
|
||||
- Config change callback notification
|
||||
@@ -1,5 +1,7 @@
|
||||
# Kenaito Config Center Go Client
|
||||
|
||||
[English](README_EN.md) | 中文
|
||||
|
||||
Go 语言的配置中心客户端 SDK。
|
||||
|
||||
## 功能特性
|
||||
|
||||
@@ -0,0 +1,144 @@
|
||||
# Kenaito Config Center Go Client
|
||||
|
||||
Go client SDK for the Kenaito Config Center.
|
||||
|
||||
## Features
|
||||
|
||||
- Fetch application configs from the config center
|
||||
- Periodic config sync
|
||||
- Config change callback listener
|
||||
- Local file cache (fallback when config center is unavailable)
|
||||
|
||||
## Installation
|
||||
|
||||
### Option 1: Using go mod (Recommended)
|
||||
|
||||
Run in your project root:
|
||||
|
||||
```bash
|
||||
go get kenaito-conf/go-client
|
||||
```
|
||||
|
||||
### Option 2: Local Development
|
||||
|
||||
If you are developing or modifying the client code locally, use the `replace` directive:
|
||||
|
||||
```bash
|
||||
# Add to your go.mod
|
||||
require kenaito-conf/go-client v0.0.0
|
||||
|
||||
replace kenaito-conf/go-client => ../kenaito-conf-go-client
|
||||
```
|
||||
|
||||
Then run:
|
||||
|
||||
```bash
|
||||
go mod tidy
|
||||
```
|
||||
|
||||
## Quick Start
|
||||
|
||||
```go
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"kenaito-conf/go-client"
|
||||
"log"
|
||||
)
|
||||
|
||||
func main() {
|
||||
// Create config
|
||||
cfg := &client.Config{
|
||||
BaseURL: "http://localhost:8080",
|
||||
AppName: "my-app",
|
||||
Env: "daily",
|
||||
Version: "latest",
|
||||
Token: "", // Optional, if app token verification is enabled
|
||||
SyncInterval: 30, // Sync interval in seconds
|
||||
CacheDir: ".", // Cache directory
|
||||
}
|
||||
|
||||
// Create client
|
||||
c := client.New(cfg)
|
||||
|
||||
// Register config change callback
|
||||
c.OnChange(func(changed map[string]string) {
|
||||
fmt.Println("Config changed:")
|
||||
for k, v := range changed {
|
||||
fmt.Printf(" %s = %s\n", k, v)
|
||||
}
|
||||
})
|
||||
|
||||
// Start client (fetch configs + enable periodic sync)
|
||||
if err := c.Start(); err != nil {
|
||||
log.Fatalf("Failed to start: %v", err)
|
||||
}
|
||||
defer c.Stop()
|
||||
|
||||
// Read config
|
||||
value := c.Get("database.host")
|
||||
fmt.Printf("database.host = %s\n", value)
|
||||
|
||||
// Get all configs
|
||||
all := c.GetAll()
|
||||
for k, v := range all {
|
||||
fmt.Printf("%s = %s\n", k, v)
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Configuration
|
||||
|
||||
| Parameter | Type | Description | Default |
|
||||
|-----------|------|-------------|---------|
|
||||
| `BaseURL` | string | Config center URL | Required |
|
||||
| `AppName` | string | Application name | Required |
|
||||
| `Env` | string | Environment (dev/daily/prod) | `dev` |
|
||||
| `Version` | string | Config version | `latest` |
|
||||
| `Token` | string | App token (if token verification is enabled) | Empty |
|
||||
| `SyncInterval` | int | Sync interval (seconds) | `60` |
|
||||
| `IgnoreGlobal` | bool | Whether to ignore global configs | `false` |
|
||||
| `CacheDir` | string | Local cache directory | `.` |
|
||||
|
||||
## API Reference
|
||||
|
||||
### `client.New(cfg *Config) *Client`
|
||||
|
||||
Create a client instance.
|
||||
|
||||
### `(*Client).Start() error`
|
||||
|
||||
Start the client, fetch configs and enable periodic sync.
|
||||
|
||||
### `(*Client).Stop()`
|
||||
|
||||
Stop the client and disable periodic sync.
|
||||
|
||||
### `(*Client).Get(key string) string`
|
||||
|
||||
Get the value of a specific config entry.
|
||||
|
||||
### `(*Client).GetAll() map[string]string`
|
||||
|
||||
Get all config entries.
|
||||
|
||||
### `(*Client).OnChange(handler func(map[string]string))`
|
||||
|
||||
Register a config change callback. The function is called when configs change, with the changed key-value pairs as argument.
|
||||
|
||||
## Demo
|
||||
|
||||
See the full example at: [kenaito-conf-go-client-demo](../kenaito-conf-go-client-demo)
|
||||
|
||||
Run the demo:
|
||||
|
||||
```bash
|
||||
cd kenaito-conf-go-client-demo
|
||||
go run main.go
|
||||
```
|
||||
|
||||
## Notes
|
||||
|
||||
1. **Token Verification**: If the app has a token configured, pass the correct token value in `Config.Token`
|
||||
2. **Cache File**: The client creates a `config-cache.json` file in the `CacheDir` directory as a fallback when the config center is unavailable
|
||||
@@ -1,5 +1,7 @@
|
||||
# Kenaito Config Center Lua Client
|
||||
|
||||
[English](README_EN.md) | 中文
|
||||
|
||||
Lua 客户端 SDK,适用于 Lua 5.1+ 项目。
|
||||
|
||||
## 安装
|
||||
|
||||
@@ -0,0 +1,95 @@
|
||||
# Kenaito Config Center Lua Client
|
||||
|
||||
Lua client SDK for the Kenaito Config Center, suitable for Lua 5.1+ projects.
|
||||
|
||||
## Installation
|
||||
|
||||
### Using LuaRocks (Recommended)
|
||||
|
||||
```bash
|
||||
cd kenaito-conf-lua-client
|
||||
luarocks make
|
||||
```
|
||||
|
||||
### Manual Install
|
||||
|
||||
Copy the `kenaito_conf` directory to your Lua path, or add it to `package.path`:
|
||||
|
||||
```lua
|
||||
package.path = package.path .. ";/path/to/kenaito-conf-lua-client/?.lua"
|
||||
```
|
||||
|
||||
## Dependencies
|
||||
|
||||
- Lua 5.1+
|
||||
- LuaSocket (`luasocket`)
|
||||
- dkjson (`dkjson`)
|
||||
|
||||
## Usage
|
||||
|
||||
```lua
|
||||
local kenaito = require("kenaito_conf")
|
||||
|
||||
local config = kenaito.Config.new({
|
||||
base_url = "http://localhost:8080",
|
||||
app_name = "my-app",
|
||||
env = "daily",
|
||||
sync_interval = 10
|
||||
})
|
||||
|
||||
local client = kenaito.Client.new({ config = config })
|
||||
|
||||
-- Listen for config changes
|
||||
client:on_change(function(changed)
|
||||
for k, v in pairs(changed) do
|
||||
print("config changed: " .. k .. " = " .. v)
|
||||
end
|
||||
end)
|
||||
|
||||
-- Start client (fetch configs)
|
||||
client:start()
|
||||
|
||||
-- Get config
|
||||
local value = client:get("database.host")
|
||||
local all = client:get_all()
|
||||
|
||||
-- Manual sync
|
||||
client:sync_once()
|
||||
|
||||
-- Stop
|
||||
client:stop()
|
||||
```
|
||||
|
||||
## Configuration
|
||||
|
||||
| Parameter | Description | Default |
|
||||
|-----------|-------------|---------|
|
||||
| `base_url` | Config center URL | `http://localhost:8080` |
|
||||
| `app_name` | Application name | (Required) |
|
||||
| `env` | Environment | `dev` |
|
||||
| `version` | Config version | `latest` |
|
||||
| `token` | App token | Empty |
|
||||
| `sync_interval` | Sync interval (seconds) | `10` |
|
||||
| `ignore_global` | Whether to ignore global configs | `false` |
|
||||
| `cache_dir` | Cache directory | `.` |
|
||||
|
||||
## Demo
|
||||
|
||||
```bash
|
||||
cd kenaito-conf-lua-client-demo
|
||||
lua app.lua
|
||||
```
|
||||
|
||||
## Environment Variables
|
||||
|
||||
The demo supports the following environment variables:
|
||||
|
||||
| Variable | Description | Default |
|
||||
|----------|-------------|---------|
|
||||
| `KENAITO_BASE_URL` | Config center URL | `http://localhost:8080` |
|
||||
| `KENAITO_APP_NAME` | Application name | `kenaito-springboot-demo` |
|
||||
| `KENAITO_ENV` | Environment | `daily` |
|
||||
| `KENAITO_VERSION` | Config version | `latest` |
|
||||
| `KENAITO_TOKEN` | App token | Empty |
|
||||
| `KENAITO_SYNC_INTERVAL` | Sync interval (seconds) | `10` |
|
||||
| `KENAITO_CACHE_DIR` | Cache directory | `.` |
|
||||
@@ -1,5 +1,7 @@
|
||||
# Kenaito Config Center Node.js Client
|
||||
|
||||
[English](README_EN.md) | 中文
|
||||
|
||||
## 安装
|
||||
|
||||
### 安装到本地仓库(推荐)
|
||||
|
||||
@@ -0,0 +1,101 @@
|
||||
# Kenaito Config Center Node.js Client
|
||||
|
||||
Node.js client SDK for the Kenaito Config Center.
|
||||
|
||||
## Installation
|
||||
|
||||
### Install to Local Repository (Recommended)
|
||||
|
||||
Register the package as a global symlink, then reference it from any project via `npm link kenaito-conf`:
|
||||
|
||||
```bash
|
||||
cd kenaito-conf-nodejs-client
|
||||
npm link
|
||||
```
|
||||
|
||||
In your project:
|
||||
|
||||
```bash
|
||||
npm link kenaito-conf
|
||||
```
|
||||
|
||||
### Direct Reference
|
||||
|
||||
```bash
|
||||
# In your project's package.json
|
||||
"dependencies": {
|
||||
"kenaito-conf": "file:../kenaito-conf-nodejs-client"
|
||||
}
|
||||
```
|
||||
|
||||
```bash
|
||||
npm install
|
||||
```
|
||||
|
||||
## Quick Start
|
||||
|
||||
```javascript
|
||||
import { Config, ConfigClient } from 'kenaito-conf';
|
||||
|
||||
const config = new Config({
|
||||
baseUrl: 'http://localhost:8080',
|
||||
appName: 'my-app',
|
||||
env: 'daily',
|
||||
syncInterval: 30,
|
||||
});
|
||||
|
||||
const client = new ConfigClient(config);
|
||||
|
||||
// Listen for config changes
|
||||
client.onChange((changed) => {
|
||||
for (const [k, v] of Object.entries(changed)) {
|
||||
console.log(`config changed: ${k} = ${v}`);
|
||||
}
|
||||
});
|
||||
|
||||
// Start client (fetch configs + enable periodic sync)
|
||||
await client.start();
|
||||
|
||||
// Get config
|
||||
const value = client.get('database.host');
|
||||
const allConfigs = client.getAll();
|
||||
|
||||
// Stop
|
||||
client.stop();
|
||||
```
|
||||
|
||||
## Configuration
|
||||
|
||||
| Parameter | Description | Default |
|
||||
|-----------|-------------|---------|
|
||||
| `baseUrl` | Config center URL | Required |
|
||||
| `appName` | Application name | Required |
|
||||
| `env` | Environment (dev/daily/prod) | `dev` |
|
||||
| `version` | Config version | `latest` |
|
||||
| `token` | Auth token | Empty |
|
||||
| `syncInterval` | Sync interval (seconds) | `60` |
|
||||
| `ignoreGlobal` | Whether to ignore global configs | `false` |
|
||||
| `cacheDir` | Local cache directory | `.` |
|
||||
|
||||
## Demo
|
||||
|
||||
```bash
|
||||
cd kenaito-conf-nodejs-client-demo
|
||||
npm install
|
||||
node app.js
|
||||
```
|
||||
|
||||
The demo listens on port `8083` by default. Visit `http://localhost:8083/` to view configs.
|
||||
|
||||
Environment variable overrides:
|
||||
|
||||
| Environment Variable | Description | Default |
|
||||
|----------------------|-------------|---------|
|
||||
| `SERVER_PORT` | Server port | `8083` |
|
||||
| `KENAITO_BASE_URL` | Config center URL | `http://localhost:8080` |
|
||||
| `KENAITO_APP_NAME` | Application name | `kenaito-nodejs-demo` |
|
||||
| `KENAITO_PROFILE` | Environment | `daily` |
|
||||
| `KENAITO_VERSION` | Config version | `latest` |
|
||||
| `KENAITO_TOKEN` | Auth token | Empty |
|
||||
| `KENAITO_SYNC_INTERVAL` | Sync interval (seconds) | `30` |
|
||||
| `KENAITO_CACHE_DIR` | Cache directory | `.` |
|
||||
@@ -1,5 +1,7 @@
|
||||
# Kenaito Config Center Perl Client
|
||||
|
||||
[English](README_EN.md) | 中文
|
||||
|
||||
Perl 客户端 SDK,适用于 Perl 5.16+ 项目。
|
||||
|
||||
## 安装
|
||||
|
||||
@@ -0,0 +1,89 @@
|
||||
# Kenaito Config Center Perl Client
|
||||
|
||||
Perl client SDK for the Kenaito Config Center, suitable for Perl 5.16+ projects.
|
||||
|
||||
## Installation
|
||||
|
||||
### Install from Local
|
||||
|
||||
```bash
|
||||
cd kenaito-conf-perl-client
|
||||
cpanm .
|
||||
```
|
||||
|
||||
### Development Mode (Symlink)
|
||||
|
||||
Add the lib path in your demo project:
|
||||
|
||||
```perl
|
||||
use lib '/path/to/kenaito-conf-perl-client/lib';
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
```perl
|
||||
use Kenaito::Conf::Config;
|
||||
use Kenaito::Conf::Client;
|
||||
|
||||
my $cfg = Kenaito::Conf::Config->new(
|
||||
base_url => 'http://localhost:8080',
|
||||
app_name => 'my-app',
|
||||
env => 'daily',
|
||||
version => 'latest',
|
||||
token => '',
|
||||
sync_interval => 10,
|
||||
cache_dir => '.',
|
||||
);
|
||||
|
||||
my $client = Kenaito::Conf::Client->new(config => $cfg);
|
||||
|
||||
# Listen for config changes
|
||||
$client->on_change(sub {
|
||||
my ($changed) = @_;
|
||||
for my $k (keys %$changed) {
|
||||
print "config changed: $k = $changed->{$k}\n";
|
||||
}
|
||||
});
|
||||
|
||||
# Start client (fetch configs)
|
||||
$client->start();
|
||||
|
||||
# Get config
|
||||
my $value = $client->get('database.host');
|
||||
my $all = $client->get_all();
|
||||
|
||||
# Manual sync
|
||||
$client->sync_once();
|
||||
|
||||
# Stop
|
||||
$client->stop();
|
||||
```
|
||||
|
||||
## Configuration
|
||||
|
||||
| Parameter | Description | Default |
|
||||
|-----------|-------------|---------|
|
||||
| `base_url` | Config center URL | `http://localhost:8080` |
|
||||
| `app_name` | Application name | (Required) |
|
||||
| `env` | Environment | `dev` |
|
||||
| `version` | Config version | `latest` |
|
||||
| `token` | App token | Empty |
|
||||
| `sync_interval` | Sync interval (seconds) | `60` |
|
||||
| `ignore_global` | Whether to ignore global configs | `0` |
|
||||
| `cache_dir` | Cache directory | `.` |
|
||||
|
||||
## Dependencies
|
||||
|
||||
- Perl 5.16+
|
||||
- HTTP::Tiny
|
||||
- JSON::PP
|
||||
|
||||
## Demo
|
||||
|
||||
```bash
|
||||
cd kenaito-conf-perl-client-demo
|
||||
KENAITO_BASE_URL=http://localhost:8080 \
|
||||
KENAITO_APP_NAME=kenaito-springboot-demo \
|
||||
KENAITO_ENV=daily \
|
||||
perl app.pl
|
||||
```
|
||||
@@ -1,5 +1,7 @@
|
||||
# Kenaito Config Center PHP Client
|
||||
|
||||
[English](README_EN.md) | 中文
|
||||
|
||||
PHP 客户端 SDK,适用于 PHP 7.4+ 项目。
|
||||
|
||||
## 安装
|
||||
|
||||
@@ -0,0 +1,102 @@
|
||||
# Kenaito Config Center PHP Client
|
||||
|
||||
PHP client SDK for the Kenaito Config Center, suitable for PHP 7.4+ projects.
|
||||
|
||||
## Installation
|
||||
|
||||
### Using Composer (Recommended)
|
||||
|
||||
```bash
|
||||
cd kenaito-conf-php-client
|
||||
composer install
|
||||
```
|
||||
|
||||
In your project:
|
||||
|
||||
```bash
|
||||
composer require kenaito/conf-client
|
||||
```
|
||||
|
||||
### Manual Include
|
||||
|
||||
```php
|
||||
require_once '/path/to/kenaito-conf-php-client/autoload.php';
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
```php
|
||||
require_once 'vendor/autoload.php';
|
||||
|
||||
use Kenaito\Conf\Config;
|
||||
use Kenaito\Conf\Client;
|
||||
|
||||
$config = new Config([
|
||||
'baseUrl' => 'http://localhost:8080',
|
||||
'appName' => 'my-app',
|
||||
'env' => 'daily',
|
||||
'syncInterval' => 10,
|
||||
]);
|
||||
|
||||
$client = new Client($config);
|
||||
|
||||
// Listen for config changes
|
||||
$client->onChange(function(array $changed) {
|
||||
foreach ($changed as $key => $value) {
|
||||
echo "config changed: $key = $value\n";
|
||||
}
|
||||
});
|
||||
|
||||
// Start client (fetch configs)
|
||||
$client->start();
|
||||
|
||||
// Get config
|
||||
$value = $client->get('database.host');
|
||||
$all = $client->getAll();
|
||||
|
||||
// Manual sync
|
||||
$client->syncOnce();
|
||||
|
||||
// Stop
|
||||
$client->stop();
|
||||
```
|
||||
|
||||
## Configuration
|
||||
|
||||
| Parameter | Description | Default |
|
||||
|-----------|-------------|---------|
|
||||
| `baseUrl` | Config center URL | `http://localhost:8080` |
|
||||
| `appName` | Application name | (Required) |
|
||||
| `env` | Environment | `dev` |
|
||||
| `version` | Config version | `latest` |
|
||||
| `token` | App token | Empty |
|
||||
| `syncInterval` | Sync interval (seconds) | `10` |
|
||||
| `ignoreGlobal` | Whether to ignore global configs | `false` |
|
||||
| `cacheDir` | Cache directory | `.` |
|
||||
|
||||
## Dependencies
|
||||
|
||||
- PHP 7.4+
|
||||
- ext-curl
|
||||
- ext-json
|
||||
|
||||
## Demo
|
||||
|
||||
```bash
|
||||
cd kenaito-conf-php-client-demo
|
||||
php app.php
|
||||
```
|
||||
|
||||
## Environment Variables
|
||||
|
||||
The demo supports the following environment variables:
|
||||
|
||||
| Variable | Description | Default |
|
||||
|----------|-------------|---------|
|
||||
| `KENAITO_BASE_URL` | Config center URL | `http://localhost:8080` |
|
||||
| `KENAITO_APP_NAME` | Application name | `kenaito-springboot-demo` |
|
||||
| `KENAITO_ENV` | Environment | `daily` |
|
||||
| `KENAITO_VERSION` | Config version | `latest` |
|
||||
| `KENAITO_TOKEN` | App token | Empty |
|
||||
| `KENAITO_SYNC_INTERVAL` | Sync interval (seconds) | `10` |
|
||||
| `KENAITO_CACHE_DIR` | Cache directory | `.` |
|
||||
@@ -1,5 +1,7 @@
|
||||
# Kenaito Config Center Python Client
|
||||
|
||||
[English](README_EN.md) | 中文
|
||||
|
||||
## 安装
|
||||
|
||||
```bash
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
# Kenaito Config Center Python Client
|
||||
|
||||
Python client SDK for the Kenaito Config Center.
|
||||
|
||||
## Installation
|
||||
|
||||
```bash
|
||||
cd kenaito-conf-python-client
|
||||
pip3 install -e .
|
||||
```
|
||||
|
||||
## Quick Start
|
||||
|
||||
```python
|
||||
from kenaito_conf import Config, ConfigClient
|
||||
|
||||
config = Config(
|
||||
base_url="http://localhost:8080",
|
||||
app_name="my-app",
|
||||
env="daily",
|
||||
sync_interval=30,
|
||||
)
|
||||
|
||||
client = ConfigClient(config)
|
||||
|
||||
# Listen for config changes
|
||||
def on_change(changed):
|
||||
for k, v in changed.items():
|
||||
print(f"config changed: {k} = {v}")
|
||||
|
||||
client.on_change(on_change)
|
||||
|
||||
# Start client (fetch configs + enable periodic sync)
|
||||
client.start()
|
||||
|
||||
# Get config
|
||||
value = client.get("database.host")
|
||||
all_configs = client.get_all()
|
||||
|
||||
# Stop
|
||||
client.stop()
|
||||
```
|
||||
|
||||
## Configuration
|
||||
|
||||
| Parameter | Description | Default |
|
||||
|-----------|-------------|---------|
|
||||
| `base_url` | Config center URL | Required |
|
||||
| `app_name` | Application name | Required |
|
||||
| `env` | Environment (dev/daily/prod) | `dev` |
|
||||
| `version` | Config version | `latest` |
|
||||
| `token` | Auth token | Empty |
|
||||
| `sync_interval` | Sync interval (seconds) | `60` |
|
||||
| `ignore_global` | Whether to ignore global configs | `False` |
|
||||
| `cache_dir` | Local cache directory | `.` |
|
||||
|
||||
## Demo
|
||||
|
||||
```bash
|
||||
cd kenaito-conf-python-client-demo
|
||||
pip3 install -r requirements.txt
|
||||
python3 app.py
|
||||
```
|
||||
|
||||
The demo listens on port `8082` by default. Visit `http://localhost:8082/` to view configs.
|
||||
|
||||
Environment variable overrides:
|
||||
|
||||
| Environment Variable | Description | Default |
|
||||
|----------------------|-------------|---------|
|
||||
| `SERVER_PORT` | Server port | `8082` |
|
||||
| `KENAITO_BASE_URL` | Config center URL | `http://localhost:8080` |
|
||||
| `KENAITO_APP_NAME` | Application name | `kenaito-springboot-demo` |
|
||||
| `KENAITO_PROFILE` | Environment | `daily` |
|
||||
| `KENAITO_VERSION` | Config version | `latest` |
|
||||
| `KENAITO_TOKEN` | Auth token | Empty |
|
||||
| `KENAITO_SYNC_INTERVAL` | Sync interval (seconds) | `30` |
|
||||
| `KENAITO_CACHE_DIR` | Cache directory | `.` |
|
||||
@@ -1,5 +1,7 @@
|
||||
# Kenaito Config Center Spring Boot 2 Client
|
||||
|
||||
[English](README_EN.md) | 中文
|
||||
|
||||
适用于 Spring Boot 2.x 应用的配置中心客户端,支持配置自动刷新和 `@Value` 注解动态更新。
|
||||
|
||||
## 安装
|
||||
|
||||
@@ -0,0 +1,165 @@
|
||||
# Kenaito Config Center Spring Boot 2 Client
|
||||
|
||||
Config center client for Spring Boot 2.x applications, supporting automatic config refresh and dynamic `@Value` annotation updates.
|
||||
|
||||
## Installation
|
||||
|
||||
### Maven Dependency
|
||||
|
||||
```xml
|
||||
<dependency>
|
||||
<groupId>cn.odboy</groupId>
|
||||
<artifactId>kenaito-conf-springboot2-client</artifactId>
|
||||
<version>1.0.3</version>
|
||||
</dependency>
|
||||
```
|
||||
|
||||
### Local Install (Development)
|
||||
|
||||
```bash
|
||||
cd kenaito-conf-springboot2-client
|
||||
mvn clean install
|
||||
```
|
||||
|
||||
## Quick Start
|
||||
|
||||
### 1. Configuration File
|
||||
|
||||
Add config center connection parameters in `application.properties`:
|
||||
|
||||
```properties
|
||||
# Config center URL
|
||||
kenaito.configcenter.base-url=http://localhost:8080
|
||||
|
||||
# Application name (required)
|
||||
kenaito.configcenter.app-name=my-app
|
||||
|
||||
# Environment (dev/daily/prod)
|
||||
kenaito.configcenter.env=daily
|
||||
|
||||
# Config version
|
||||
kenaito.configcenter.version=latest
|
||||
|
||||
# Auth token (optional)
|
||||
kenaito.configcenter.token=your-token
|
||||
|
||||
# Whether to enable remote config (default true)
|
||||
kenaito.configcenter.enabled=true
|
||||
|
||||
# Sync interval in seconds (default 10)
|
||||
kenaito.configcenter.sync-interval=10
|
||||
|
||||
# Sensitive config keys (for log masking, optional)
|
||||
kenaito.configcenter.sensitive-keys=password,secret,key,token
|
||||
```
|
||||
|
||||
### 2. Inject Configs with @Value
|
||||
|
||||
```java
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
|
||||
@RestController
|
||||
public class ConfigController {
|
||||
|
||||
@Value("${database.host:localhost}")
|
||||
private String databaseHost;
|
||||
|
||||
@Value("${database.port:3306}")
|
||||
private Integer databasePort;
|
||||
|
||||
@Value("${kenaito.feature.enabled:false}")
|
||||
private Boolean featureEnabled;
|
||||
|
||||
@GetMapping("/config")
|
||||
public Map<String, Object> getConfig() {
|
||||
Map<String, Object> config = new HashMap<>();
|
||||
config.put("databaseHost", databaseHost);
|
||||
config.put("databasePort", databasePort);
|
||||
config.put("featureEnabled", featureEnabled);
|
||||
return config;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 3. Automatic Config Refresh
|
||||
|
||||
When configs change in the config center, the client automatically refreshes `@Value` annotated fields without restarting the application.
|
||||
|
||||
**Config change listener log:**
|
||||
```
|
||||
[RefreshScope] Refreshed @Value field: ConfigController.databaseHost | old='localhost' | new='192.168.1.100' | converted='192.168.1.100' | verify='192.168.1.100' | success=true
|
||||
```
|
||||
|
||||
### 4. Using @ConfigurationProperties
|
||||
|
||||
```java
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
@ConfigurationProperties(prefix = "database")
|
||||
public class DatabaseProperties {
|
||||
|
||||
private String host;
|
||||
private Integer port;
|
||||
private String username;
|
||||
private String password;
|
||||
|
||||
// getters and setters
|
||||
}
|
||||
```
|
||||
|
||||
## Configuration Properties
|
||||
|
||||
| Property | Description | Default | Required |
|
||||
|----------|-------------|---------|----------|
|
||||
| `kenaito.configcenter.base-url` | Config center URL | - | Yes |
|
||||
| `kenaito.configcenter.app-name` | Application name | - | Yes |
|
||||
| `kenaito.configcenter.env` | Environment | `dev` | No |
|
||||
| `kenaito.configcenter.version` | Config version | `latest` | No |
|
||||
| `kenaito.configcenter.token` | Auth token | Empty | No |
|
||||
| `kenaito.configcenter.enabled` | Whether to enable | `true` | No |
|
||||
| `kenaito.configcenter.sync-interval` | Sync interval (seconds) | `10` | No |
|
||||
| `kenaito.configcenter.sensitive-keys` | Sensitive keys (log masking) | Empty | No |
|
||||
|
||||
## Auto Configuration
|
||||
|
||||
The client works via Spring Boot auto-configuration:
|
||||
|
||||
- **KenaitoEnvironmentInitializer**: Initializes the config center connection
|
||||
- **KenaitoRefreshAutoConfiguration**: Registers the config refresh listener
|
||||
|
||||
No manual Bean configuration needed — just add the dependency and configure the properties.
|
||||
|
||||
## Demo
|
||||
|
||||
Run the demo project:
|
||||
|
||||
```bash
|
||||
cd kenaito-conf-springboot2-client-demo
|
||||
mvn spring-boot:run
|
||||
```
|
||||
|
||||
Demo defaults:
|
||||
- Port: 8083
|
||||
- App name: `kenaito-springboot2-demo`
|
||||
- Environment: `daily`
|
||||
- Config center URL: `http://localhost:8080`
|
||||
|
||||
Visit `http://localhost:8083/config` to view current configs.
|
||||
|
||||
## Notes
|
||||
|
||||
1. **@Value Refresh Limitation**: Only supports primitive types (String, Integer, Boolean, Long, Double, etc.) and their wrapper classes
|
||||
2. **Config Priority**: Remote config > Local config > Default value
|
||||
3. **Log Masking**: Configs containing sensitive keys are automatically masked in logs (first half + `****`)
|
||||
4. **Network Errors**: Sync failures are logged as errors without affecting normal application operation
|
||||
|
||||
## Changelog
|
||||
|
||||
- **1.0.3** - Simplified config refresh logic, removed EnvironmentChangeEvent wrapper
|
||||
- **1.0.2** - Added sensitive config masking support
|
||||
- **1.0.1** - Added sync interval configuration
|
||||
- **1.0.0** - Initial release
|
||||
Reference in New Issue
Block a user