服务运行时可以经过外部动态修改的参数既是配置。在运行时动态变动服务的行为,避免业务发生变动须要修改代码或重启服务等等。html
duic 是配置管理中心,将配置统一管理提供标准的配置格式及编辑方式。
设计目标是统一不一样应用的配置管理方式,打造更人性化的配置编辑方式,提供更灵活的配置获取方式。java
如上图:duic 支持任何应用,任何语言的配置管理(Java,Go,Android,Web等),同时 duic 采用 YAML 语法做用配置文件格式,支持数据类型及结构化配置。mysql
如上图采用 YAML 编辑好配置以后经过 RESTful 接口获取配置(PS:官方目前已经提供Java、Android、Go语言的SDK,后期还会支持更多语言)。git
key=value
格式的不足开箱即用,duic 每一个 release 版本均可以经过 GitHub Releases 获取 jar 包部署,或者你能够在 Docker Hub 获取 Docker 镜像直接部署。你只须要关注如何使用 duic,而无需关心内部的实现细节,固然你若是对实现细节感兴趣,很是欢迎帮忙审查代码,你的帮助可让 duic 的代码变得更加精练。github
在 GitHub Releases 页下载最新版本的 duic-x.x.x.jar 文件。spring
Java >= 1.8
MySQL >= 5.6sql
CREATE DATABASE IF NOT EXISTS `duic` CHARACTER SET utf8mb4 COLLATE utf8mb4_bin;
application.ymldocker
spring: datasource: url: jdbc:mysql://127.0.0.1:3306/duic?autoReconnect=true&useServerPrepStmts=true username: root password: root
PS:将application.yml
文件与 duic-x.x.x.jar 文件放置在同一目录中。duic 是采用 spring-boot 开发,配置文件目录完成遵照 spring-boot 默认加载方式,更多关于 spring-boot 配置能够了解数据库
java -Dspring.profiles.active=mysql -jar duic.jar
输出以下日志时,恭喜你 duic 已经启动成功。编程
______ _ ______ |_ _ `. (_) .' ___ | | | `. \ __ _ __ / .' \_| | | | |[ | | | [ || | _| |_.' / | \_/ |, | |\ `.___.'\ |______.' '.__.'_/[___]`.____ .' :: duic :: (v1.5.2-SNAPSHOT) 2018-05-03 07:06:05,980 INFO i.z.d.server.Application$Companion - Starting Application.Companion v1.5.2-SNAPSHOT on ubuntu with PID 47440 (/opt/duic/duic.jar started by zy in /opt/duic) 2018-05-03 07:06:05,984 INFO i.z.d.server.Application$Companion - The following profiles are active: mysql,prod 2018-05-03 07:06:09,595 INFO r.i.netty.tcp.BlockingNettyContext - Started HttpServer on /0:0:0:0:0:0:0:0%0:7777 2018-05-03 07:06:09,596 INFO o.s.b.w.e.netty.NettyWebServer - Netty started on port(s): 7777 2018-05-03 07:06:09,600 INFO i.z.d.server.Application$Companion - Started Application.Companion in 4.192 seconds (JVM running for 4.864)
http://[IP]:7777/index.html
PS:记得将 IP 替换为你服务的 IP。
关于 duic 部署在这里就写这么多了,有任何问题请给我留言,我将一一解答,更多关于 duic 部署方面的内容,你们能够参考官方提供的文档 DuiC Wiki。
https://duic.zhudy.io/index.html
添加 Maven 依赖
<dependency> <groupId>io.zhudy.duic</groupId> <artifactId>duic-spring-cloud-config-client</artifactId> <version>2.0.1</version> </dependency>
添加 Gradle 依赖
compile "io.zhudy.duic:duic-spring-cloud-config-client:2.0.1"
在 bootstrap.yml
配置文件中添加获取配置信息
duic: spring: cloud: config: uri: https://duic.zhudy.io/api/v1 name: hello profile: first # token: [TOKEN]
uri
配置中心地址前缀name
配置名称profile
配置环境名称,多个采用,
分隔配置完成后在 spring-boot 项目中便可使用 @ConfigurationProperties
@Value
方式注入配置依赖,duic 并无提供任何自定义注解,彻底遵照 spring-boot 的编程习惯,无缝接入及移除 duic。
GitHub: duic-spring-cloud-config-client
添加 Maven 依赖
<dependency> <groupId>io.zhudy.duic</groupId> <artifactId>duic-spring-cloud-config-client</artifactId> <version>2.0.1</version> </dependency>
添加 Gradle 依赖
compile "io.zhudy.duic:duic-spring-cloud-config-client:2.0.1"
<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="first"/> </bean>
配置完成 spring bean 以后在项目中便可使用 @Value
注入配置,彻底兼容 spring 编程习惯,支持配置热加载。
GitHub: duic-java-client
引入 duic-go-client 依赖包
go get -u github.com/zhudyos/duic-go-client
初始化配置信息
duic.BaseUri = "https://duic.zhudy.io/api/v1" duic.Name = "hello" duic.Profiles = "first" duic.Init()
获取配置
duic.Bool("key") // 获取一个 bool 配置 duic.Int("key") // 获取一个 int 配置 duic.Float64("key") // 获取一个 float64 配置 duic.String("key") // 获取一个 string 配置 duic.Array("key") // 获取一个数组配置 duic.Object("key") // 获取一个对象配置
欢迎 PR!!!
GitHub: https://github.com/zhudyos/duic
QQ群:540315111