日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

DuiC 统一配置管理 2

發(fā)布時間:2025/7/14 编程问答 89 豆豆
生活随笔 收集整理的這篇文章主要介紹了 DuiC 统一配置管理 2 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

為什么設(shè)計 DuiC

在工作中我們時常要根據(jù)不同環(huán)境配置不同的參數(shù),讓項目的靈活性、可用性變得更高,那靈活的配置就變得必不可少,雖然目前已經(jīng)存在很多配置管理解決方案,但是管理方式局限性大,適應(yīng)范圍窄。

DuiC 在設(shè)計初就考慮到配置的應(yīng)用范圍,將配置獲取方式設(shè)計為 RESTful API 的方式,可支持任何服務(wù)器端,客戶端以及 WEB 輕松獲取配置。其次 DuiC 管理配置統(tǒng)一采用 YAML 的方式,并提供 WEB 編輯器及語法高亮,語法校驗等功能,降低配置修改的錯誤率。

DuiC 源碼: https://github.com/zhudyos/duic

已實現(xiàn)的功能

  • 檢查配置狀態(tài)
  • 通過 key 獲取某個配置
  • 通過 name/profile 獲取整體配置
  • 多個 profile 配置深度合并
  • 配置權(quán)限管理
  • 分布式配置管理
  • 容器部署
  • Swagger 文檔: https://app.swaggerhub.com/ap...
    Docker 鏡像: https://hub.docker.com/r/zhud...

    Java Client API

    DuiC 提供 Java 客戶端 API 幫助你快速獲取配置,支持 Android/Java/JavaWeb/Spring 獲取配置同時支持熱加載配置。

    duic-java-client:https://github.com/zhudyos/du...

    Java/Android 使用

    使用 API 提供的 ConfigUtils 工具包獲取配置。
    創(chuàng)建 Config 實例并將設(shè)置為 ConfigUtils 的默認配置,使用。

    Config config = new Config.Builder().baseUri("https://duic.zhudy.io/api/v1").name("hello").profile("world")// .configToken("...")// .reloadPlot(new ReloadPlot(10, TimeUnit.SECONDS)) // 重載// .failFast(true) // 快速失敗// .listener() // 配置加載監(jiān)聽.build(); ConfigUtils.setDefaultConfig(config);

    Java Web 使用

    使用 API 提供的 ConfigUtils 工具包獲取配置。
    在 web.xml 中配置監(jiān)聽器

    <!-- 默認配置路徑 classpath:duic.properties --> <context-param><param-name>duicConfigLocation</param-name><param-value>classpath:duic.properties</param-value> </context-param><listener><listener-class>io.zhudy.duic.config.web.DuicConfigContextListener</listener-class> </listener>

    在 duic.properties 文件中增加配置管理中心信息

    duic.base.uri=https://duic.zhudy.io/api/v1 duic.name=hello duic.profile=world duic.config.token= duic.reload.period=10 duic.reload.unit=SECONDS duic.fail.fast=false # 多個 DuicListener 采用英文逗號(,)分隔 duic.listeners=xx.MyDuicListener

    在 Spring 中使用

  • 使用 API 提供的 ConfigUtils 工具包獲取配置
  • 使用 @Value 的方式注入配置(推薦
  • 以上2種方式都支持熱加載,推薦使用 @Value 的方式注入配置,這種方式對于你的代碼沒有任何的浸入性,支持 spring3.2 以上的版本使用。

  • 使用注解的方式初始化

    @Bean public static DuicConfigBeanFactoryPostProcessor duicConfigBeanFactoryPostProcessor() {DuicConfigBeanFactoryPostProcessor processor = new DuicConfigBeanFactoryPostProcessor();processor.setBaseUri("https://duic.zhudy.io/api/v1");processor.setName("hello");processor.setProfile("world");return processor; }
  • 使用 XML 的方式初始化

    <bean id="duicConfigBeanFactoryPostProcessor" class="io.zhudy.duic.config.spring.duicConfigBeanFactoryPostProcessor"><property name="baseUri" value="https://duic.zhudy.io/api/v1"/><property name="name" value="hello"/><property name="profile" value="world"/> </bean>
  • 注入配置

    @Component public class Example {@Value("${k1.string}")private String k1; }

    Spring Boot 支持

    DuiC 也提供了 duic-spring-cloud-config-client 來支持 spring-boot,使用 DuiC 管理配置可以完全替代 spring-cloud-config。

    duic-spring-cloud-config-client:https://github.com/zhudyos/du...

    該工具包支持 @ConfigurationProperties 及 @Value 注入配置,同時也支持熱加載。
    注意如果你使用 @ConfigurationProperties 注入配置并且想要熱加載配置需要配合使用 @RefreshScope 注解。

    關(guān)于更多 @RefreshScope 的資料請查看 spring-cloud 官方文檔:https://cloud.spring.io/sprin...

    使用示例在 bootstrap.yml 文件中增加如下配置

    spring:application:name: samples (1)duic:spring:cloud:config:watch:enabled: true (2)initial_delay: 10000 (3)fixed_delay: 10000 (4)uri: https://duic.zhudy.io/api/v1 (5)profile: first,second (6)# token: [TOKEN] (7)

    duic docker-compose

    https://github.com/zhudyos/du...

    關(guān)于 DuiC 更加詳細的描述,可以查看倉庫中在 readme。

    在線演示平臺:https://duic.zhudy.io/index.html
    e-mail: kevinz@weghst.com
    password: 123456

    大家可以使用在線演示平臺,嘗試使用其提供的 API 及 SDK。
    友情提醒:服務(wù)器配置較差,訪問速度可能不是很快,請體諒。

    總結(jié)

    以上是生活随笔為你收集整理的DuiC 统一配置管理 2的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。