______ _ ______ |_ _ `. (_) .' ___ | | | `. \ __ _ __ / .' \_| | | | |[ | | | [ || | _| |_.' / | \_/ |, | |\ `.___.'\ |______.' '.__.'_/[___]`.____ .'
在軟件開發中隨着業務的須要, 需求的變動, 程序的靈活咱們時常須要在項目中設置各類開關或者配置項. 在往常時通常會採用配置文件的方式, 可是在這分佈式集羣時代採用傳統的配置管理方式顯得有點力不從心. 同時在咱們的 app/web 終端咱們也時常須要各類配置, 在面對大量的終端配置獲取請求咱們的配置中心須要高性能, 高穩定性.html
duic 的誕生並不單單只是爲了解決服務器應用的配置java
duic 是採用 spring-webflux 開發, 經過 RESTful 方式拉取配置, 支持配置合併, 內置 web 控制檯修改配置, 支持配置用戶權限設置, 支持配置訪問 IP 限制, 支持 token 限制, 支持多應用多環境變量, 支持 docker, 支持集羣nginx
GET {base_uri}/apps/states/{name}/{profile}
按需取獲取配置
你有時可能須要獲取某個 key 的配置而不是整個 profile 的配置GET {base_uri}/apps/{name}/{profile}/{key}
key 支持按 .
分隔, 父 key 能夠獲取子項的全部配置git
獲取
k1
項的配置githubrequest
$ curl https://duic.zhudy.io/api/v1/apps/sample/first/k1
responseweb{ "string":"samples first k1 string", "int":11, "array":[ 1, 2, 3 ], "multiple_lines":"sample\nfirst\nmultiple\nlines" }獲取
k1.string
項的配置springrequest
$ curl https://duic.zhudy.io/api/v1/apps/sample/first/k1.string
responsemongodb{ "value":"samples first k1 string" }
@ConfigurationProperties
@Value
註解, 同時還支持配置熱加載duic-java-client
java 版本客戶端程序docker
服務配置 application.yml數據庫
server: port: 7777 spring: jackson: default_property_inclusion: non_default date_format: yyyy-MM-dd'T'HH:mm:ss joda_date_time_format: yyyy-MM-dd'T'HH:mm:ss property_naming_strategy: CAMEL_CASE_TO_LOWER_CASE_WITH_UNDERSCORES data: mongodb: uri: mongodb://127.0.0.1:27017/duic duic: root_email: kevinz@weghst.com root_password: 123456 jwt: secret: U2FsdGVkX1/jO0KlWumac4yDM8rOgWPkaV0KrSHDynWOP6n8FMJB9uSc8EW/qM+VagrMBAXGpyw= expires_in: 180
在 docker-compose 配置中已經集成 mongodb, nginx, let’s encrypt, docker-gen 服務發現
$ git clone https://github.com/zhudyos/duic-docker-compose.git
cd duic-docker-compose
$ chmod +x start.sh
$ ./start.sh
服務配置
1. 建立 **config** 文件夾 2. 在 **config** 文件夾中建立配置文件 **application.yml** 3. **application.yml** 配置文件將 **spring.data.mongodb.uri** 鏈接地址修改成安裝服務的 MongoDB 鏈接地址
啓動容器$ docker run -d -p 7777:7777 -v $(pwd)/config:/app/config zhudyos/duic
將 application.yml 配置文件放置在 config 目錄中並掛載到容器的 /app/config 目錄中, duic 則會使用指定的配置