# rtpt
**Repository Path**: x-git/rtpt
## Basic Information
- **Project Name**: rtpt
- **Description**: SpringCloud动态参数配置
- **Primary Language**: Java
- **License**: Not specified
- **Default Branch**: master
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 0
- **Forks**: 11
- **Created**: 2018-07-20
- **Last Updated**: 2020-12-19
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
# RTPT Spring Cloud 动态配置
[](https://github.com/ihaiker/rtpt/issues)
[](https://github.com/ihaiker/rtpt/network)
[](https://github.com/ihaiker/rtpt/stargazers)


## 1. 背景
在个人开发的个人软件和公司的项目中很多地方使用到了动态配置,例如:功能参数、搜索功能权重设置、抽佣比例等。
这些配置不同于平台的静态配置(数据连接池参数等)随时会随着业务的变化而改变,且此类参数大多数属于运营参数需要给运营人员开放修改权限。如果更改就涉及代码配置的更新服务的配置重新启动,如果此类动作过于频繁导致系统集群的不稳定性增加。
## 2、简介
RTPT是作者本人一些工作中针对具体问题总结的解决方案,
本程序已经在线上运行,如果您发现软件中的BUG或者设计不合理的地方您可以直接提交 [Issues](https://github.com/ihaiker/rtpt/issues) 或者 [邮件(wo@renzhen.la)](mailto:wo@renzhen.la) 联系我.
## 3、配置详解
动态配置分为客户端、配置管理中两部分。
客户端使用分为两种:
* 单独使用,使用第三方中间件存储数据,现在客户端支持Redis,Consul两种.
* 配合管理中心一起使用
服务端:配置数据中心化管理,
数据保存支持:
* JDBC
* Redis
* Consul
无论是客户端单独使用还是配置管理中心化后期将支持更多的数据存储方案(etcd,zookeeper等)。
### 3.1、客户端配置
#### 3.1.0 导入依赖包
Maven:
```xml
la.renzhen.basis.rtpt
rtpt-client-starter
1.0.2
```
Gradle:
```groovy
compile "la.renzhen.basis.rtpt:rtpt-client-starter:1.0.2"
```
#### 3.1.1 编写配置绑定类
```java
@FluentConfiguration("demo")
public interface DemoConfig {
@Data
public class SubConfig {
String param3;
int param4;
}
@FluentConfiguration.DefaultValue("参数默认值")
String param1();
int param2();
@FluentConfiguration.DefaultValue("{\"param3\":\"参数三\"}")
SubConfig sub();
}
```
绑定类对应配置key说明:
|方法|对应key|
|-|-|
|DemoConfig#param1()|[rtpt.prefix.]demo.param1|
|DemoConfig#param2()|[rtpt.prefix.]demo.param2|
|DemoConfig#sub#param3|[rtpt.prefix.]demo.sub.param3|
|DemoConfig#sub#param4|[rtpt.prefix.]demo.sub.param4|
rptp.prefix 为客户端全局配置key前缀,详细查看客户端配置。
#### 3.1.2 客户端配置
##### 3.1.2.1 使用Redis
```
rtpt:
prefix: cfg
environment: master
redis:
address: 127.0.0.1:6379
folder: rtpt
database: 0
```
##### 3.1.2.2 使用Consul
```
rtpt:
prefix: cfg
environment: master
consul:
address: 127.0.0.1:8500
folder: rtpt
```
##### 3.1.2.3 使用Center配置中心
使用center配置中心可以有两种方式:
第一种方式:未使用注册中心
```
rtpt:
prefix: cfg
environment: master
center:
address: http://localhost:7658
contextPath: /rtpt
```
第二种方式:使用注册中心
```
rtpt:
center:
discovery:
serviceId: "rptp-config-server"
enabled: true
```
详细介绍查看:[RTTPProperties.java](https://github.com/ihaiker/rtpt/tree/master/client/src/main/java/la/renzhen/spring/boot/RTPTProperties.java)
### 3.2、配置管理中心配置
#### 3.2.1 引入依赖包
Maven:
```xml
la.renzhen.basis.rtpt
rtpt-admin-server-starter
1.2.0
```
Gradle:
```gradle
compile "la.renzhen.basis.rtpt:rtpt-admin-server-starter:1.0.0"
```
#### 3.2.2 使用Consul当中心配置存储
```
rtpt:
admin:
consul:
address: 127.0.0.1:8500
```
#### 3.2.3 使用Redis当中心配置存储
```
rtpt:
admin:
redis:
url: 127.0.0.1:6379
module: rtpt
```
#### 3.2.4 使用jdbc当中心配置存储
```
rtpt:
admin:
disable-web-ui: false
context-path: /rtpt
jdbc:
url: jdbc:mysql://127.0.0.1:3306/test
username: haiker
password: haiker
```
注:等多配置查看实例:[example](https://github.com/ihaiker/rtpt/tree/master/example)
## 4、更新历史
** 2018-06-20 V1.0.2 **
- 1、修复依赖文件BUG
- 2、修改默认scan package的方式,默认当前项目路径。放弃配置文件rptp.scan-package方式
** 2018-06-06 V1.0.0 **
第一版开源版本发布