Commit c6905a0e by 陈文顺

initial commit

parents
## apollo 接入
## apollo 接入
### 介绍
![apollo](https://github.com/ctripcorp/apollo/raw/master/doc/images/basic-architecture.png)
随着程序功能的日益复杂,程序的配置日益增多:各种功能的开关、参数的配置、服务器的地址……
对程序配置的期望值也越来越高:配置修改后实时生效,灰度发布,分环境、分集群管理配置,完善的权限、审核机制……
在这样的大环境下,传统的通过配置文件、数据库等方式已经越来越无法满足开发人员对配置管理的需求。
Apollo配置中心应运而生!
#### Apollo支持4个维度管理Key-Value格式的配置:
1. application (应用) (订单服务,券码服务.....)
2. environment (环境)(DEV、FAT、UAT、PRO)
3. cluster (集群)
4. namespace (命名空间) (application)
## 接入步骤
#### 第一步 再apollo创建应用的配置,可以copy现有的配置文件
![apollo](11_26_27__03_29_2019.jpg)
#### 第二步 maven 依赖
<dependency>
<groupId>com.ctrip.framework.apollo</groupId>
<artifactId>apollo-client</artifactId>
<version>1.1.0</version>
</dependency>
#### 第三步
spring 启动类加上注解@EnableApolloConfig
```java
@SpringBootApplication
@ComponentScan(basePackages = "com.freemud, cn.freemud")
@MapperScan(basePackages = "com.freemud.demo.mapper")
//@EnableEurekaClient
@EnableApolloConfig
public class SpringbootDemoApplication extends WebMvcConfigurerAdapter{
public static void main(String[] args) {
SpringApplication.run(SpringbootDemoApplication.class, args);
}
@Bean
public HttpMessageConverter getConverter(){
return new FastJsonpHttpMessageConverter4();
}
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**")
.allowedOrigins("*")
.allowCredentials(true)
.allowedMethods("GET", "POST", "DELETE", "PUT","PATCH")
.maxAge(3600);
}
}
```
#### 参数设置
##### 1) AppId
Spring Boot的application.properties文件配置,如
```
app.id=YOUR-APP-ID
```
##### 2)Apollo Meta Server
可以在Spring Boot的application.properties中指定,不同环境地址不同
```
apollo.meta=http://config-service-url
```
##### 3)本地缓存路径
可以在Spring Boot的application.properties中指定
```
apollo.cacheDir=/opt/data/some-cache-dir
```
#### 第四步 骤代码中使用
```
//第一种方式
@Value("${timeout:100}")
private int timeout;
@Value("${swagger_enable:false}")
String swaggerEnable;
//第二种方式
@ApolloConfig
private Config config; //inject config for namespace application
public void someMethed(){
//获取配置
String value = config.getProperty(someKey, someDefaultValue);
}
//可以监听配置变化
@ApolloConfigChangeListener
public void onChange(ConfigChangeEvent changeEvent){
System.out.println(changeEvent.changedKeys());
}
```
DEV
开发环境
FAT
测试环境,相当于alpha环境(功能测试)
UAT
集成环境,相当于beta环境(回归测试)
PRO
生产环境
配置可以有多种加载方式
配置也有很多种加载方式,常见的有程序内部hard code,配置文件,环境变量,启动参数,基于数据库等
如果Apollo部署在公有云上,本地开发环境无法连接,但又需要做开发测试的话,客户端可以升级到0.11.0版本及以上,然后通过-Dapollo.configService=http://config-service的公网IP:端口来跳过meta service的服务发现
\ No newline at end of file
## 分布式任务调度中心
## 分布式任务调度中心
测试环境管理地址:[http://172.81.206.37:9505/cron-job-queue.htm](http://172.81.206.37:9505/cron-job-queue.htm)
帐号:admin/admin
经过saas生产环境一段时间的试用,推荐给大家
采用开源lts经过简单扩展(实现通用任务触发器)
特点:对现有系统无任何侵入,不需要引入第三方库,不需要增加任何配置项;
使用方只需要提供一个接口地址,任务调度中心会根据你的配置(cron表达式)定时调用接口地址,达到定时任务的目的。
## 操作界面
![step1](lts_step1.png)
![step2](lts_step2.png)
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment