分布式配置中心 duic

栏目: Java · 发布时间: 7年前

内容简介:服务运行时能够通过外部动态修改的参数既是配置。在运行时动态变更服务的行为,避免业务发生变更需要修改代码或重启服务等等。duic 是配置管理中心,将配置统一管理提供标准的配置格式及编辑方式。设计目标是统一不同应用的配置管理方式,打造更人性化的配置编辑方式,提供更灵活的配置获取方式。

什么是配置?

服务运行时能够通过外部动态修改的参数既是配置。在运行时动态变更服务的行为,避免业务发生变更需要修改代码或重启服务等等。

什么是 duic?

duic 是配置管理中心,将配置统一管理提供标准的配置格式及编辑方式。

设计目标是统一不同应用的配置管理方式,打造更人性化的配置编辑方式,提供更灵活的配置获取方式。

分布式配置中心 duic

如上图:duic 支持任何应用,任何语言的配置管理(Java,Go,Android,Web等),同时 duic 采用 YAML 语法作用配置文件格式,支持数据类型及结构化配置。

分布式配置中心 duic

如上图采用 YAML 编辑好配置之后通过 RESTful 接口获取配置( PS:官方目前已经提供 Java 、Android、 Go 语言的SDK,后期还会支持更多语言 )。

为什么采用 YAML 作为配置格式?

key=value

特性

  • 支持 MongoDB,MySQL,PostgreSQL,Oracle 存储配置信息
  • 配置修改实时更新
  • 支持多配置合并
  • 支持按需获取配置
  • 支持历史版本比较
  • 支持配置克隆
  • 支持用户权限控制
  • 支持 IP/Token 访问限制
  • 支持 Docker

部署

开箱即用,duic 每个 release 版本都可以通过 GitHub Releases 获取 jar 包部署,或者你可以在 Docker Hub 获取 Docker 镜像直接部署。 你只需要关注如何使用 duic,而无需关心内部的实现细节,当然你如果对实现细节感兴趣,非常欢迎帮忙审查代码,你的帮助可以让 duic 的代码变得更加精练。

MySQL 部署

GitHub Releases 页下载最新版本的 duic-x.x.x.jar 文件。

前提

Java >= 1.8

MySQL >= 5.6

创建数据库

CREATE DATABASE IF NOT EXISTS `duic` CHARACTER SET utf8mb4 COLLATE utf8mb4_bin;

配置数据库连接

application.yml

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

分布式配置中心 duic

分布式配置中心 duic

spring-boot 加载配置

添加 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

spring 加载配置

添加 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

go 加载配置

引入 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


以上所述就是小编给大家介绍的《分布式配置中心 duic》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Data Structures and Algorithms in Python

Data Structures and Algorithms in Python

Michael T. Goodrich、Roberto Tamassia、Michael H. Goldwasser / John Wiley & Sons / 2013-7-5 / GBP 121.23

Based on the authors' market leading data structures books in Java and C++, this book offers a comprehensive, definitive introduction to data structures in Python by authoritative authors. Data Struct......一起来看看 《Data Structures and Algorithms in Python》 这本书的介绍吧!

MD5 加密
MD5 加密

MD5 加密工具

Markdown 在线编辑器
Markdown 在线编辑器

Markdown 在线编辑器

正则表达式在线测试
正则表达式在线测试

正则表达式在线测试