[ 
https://issues.apache.org/jira/browse/SCB-133?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16328201#comment-16328201
 ] 

ASF GitHub Bot commented on SCB-133:
------------------------------------

WillemJiang closed pull request #29: SCB-133 user guide document for dynamic 
config
URL: https://github.com/apache/incubator-servicecomb-website/pull/29
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/_data/navigation.yml b/_data/navigation.yml
index 9905397..25d50eb 100755
--- a/_data/navigation.yml
+++ b/_data/navigation.yml
@@ -84,6 +84,8 @@ t:
             url: /users/distributed-tracing/
           - title: Customized Tracing
             url: /users/customized-tracing/
+         - title: Dynamic Configurations
+           url: /users/dynamic-config/
 
       - title: Edging Service
         children:
@@ -209,6 +211,8 @@ t:
             url: /cn/users/distributed-tracing/
           - title: 自定义调用链打点
             url: /cn/users/customized-tracing/
+         - title: 动态配置
+           url: /cn/users/dynamic-config/
 
       - title: 服务能力开放
         children:
diff --git a/_users/cn/dynamic-config.md b/_users/cn/dynamic-config.md
new file mode 100644
index 0000000..d11f698
--- /dev/null
+++ b/_users/cn/dynamic-config.md
@@ -0,0 +1,105 @@
+---
+title: "动态配置"
+lang: cn
+ref: customized-tracing
+permalink: /cn/users/dynamic-config/
+excerpt: "动态配置"
+last_modified_at: 2018-01-11T15:01:43-04:00
+redirect_from:
+  - /theme-setup/
+---
+
+{% include toc %}
+## 概念阐述
+
+动态配置能够在服务运行期间对服务自身和服务依赖的配置信息进行热修改。传统的配重信息处理方式是将配置信息写入xml、properties等配置文件中和应用一起打包,每次修改配置信息都需要重新打包部署,效率极低,且由于微服务架构中应用数量,应用依赖的配置数量会使配置信息的维护非常困难。动态配置功能就是为了解决这个问题。通过配置中心对服务依赖的配置信息进行修改,服务端主动查询或者配置中心下发都可以达到不用重新部署服务而改变其配置信息的目的。Java
 Chassis目前支持对接配置中心Apollo,用户可以通过实现Java Chassis提供的扩展接口很简单的对接到其他配置中心。
+
+## 使用步骤:
+
+### 部署并启动Apollo配置中心
+
+通过镜像方式启动Apollo配置中心请参考[官方文档](https://github.com/ctripcorp/apollo/wiki/Apollo-Quick-Start-Docker%E9%83%A8%E7%BD%B2),或者执行下面两个指令即可:
+
+   ```bash
+   git clone https://github.com/lijasonvip/apollo-image-for-servicecomb.git
+   cd apollo-image-for-servicecomb && docker-compose up
+   ```
+等待出现 `Portal started. You can visit http://localhost:8070 now!` 
后表示系统启动完成,可以在浏览器中访问`http://localhost:8070`进入配置中心页面。 
`docker-compose`安装请参考[文档](https://docs.docker.com/compose/install/)。
+
+### 通过Apollo界面配置应用获取TOKEN
+
+* ##### 登录Apollo配置中心创建项目
+
+  在浏览器中输入登录地址,地址是容器所在主机的`IP:PORT`端口默认8070,如`http://192.168.199.1:8070`
+
+  ![登录配置中心](E:\opensource\dynamic 
config\incubator-servicecomb-website\assets\images\config/login.png)
+
+  Apollo配置中心的默认登录账号是apollo/admin,点击登录后会跳转到下图中的配置中心首页。
+
+* ##### 创建项目
+
+  ![创建项目](E:\opensource\dynamic 
config\incubator-servicecomb-website\assets\images\config\create_project.png)
+
+  
首页中默认展示一个示例项目SampleApp,用户可以点击创建项目自行创建一个,下图是创建项目页面,填入应用Id和应用名称,选择所在部门和应用负责人后点击提交即可。
+
+![项目信息](E:\opensource\dynamic 
config\incubator-servicecomb-website\assets\images\config\create_project2.png)
+
+* ##### 生成TOKEN
+
+打开地址`http://192.168.199.1:8070/open/manage.html`进入下图页面,填入刚才创建项目使的应用名选择相应的部门和项目负责人即可生成应用对应的TOKEN,保存这个TOKEN稍后配置到项目代码中即可。
+
+![生成TOKEN](E:\opensource\dynamic 
config\incubator-servicecomb-website\assets\images\config\token.png)
+
+### 在应用中添加依赖
+
+```xml
+    <dependency>
+          <groupId>com.netflix.archaius</groupId>
+          <artifactId>archaius-core</artifactId>
+    </dependency>   
+    <dependency>
+          <groupId>io.servicecomb</groupId>
+          <artifactId>config-apollo</artifactId>
+    </dependency>
+```
+### 添加配置项
+
+   ```yaml
+   cse:
+     config:
+       client:
+       serverUri: http://127.0.0.1:8070
+   apollo:
+     config:
+       serverUri: http://127.0.0.1:8070
+       serviceName: SampleApp
+       env: DEV
+       clusters: default
+       namespace: application
+       token: testtoken
+       refreshInterval: 10
+   ```
+​      
`cse.config.client.serverUri`配置项填写Apollo配置中心portal服务地址,只是表示对接配置中心,`apollo.config`下的配置项是用户创建的应用参数,包括服务地址,用户名,集群,namespace,token等参数。这些参数可以在配置中心页面项目信息栏中查到。需要注意的是`refreshInterval:
 10`表示应用会每隔10秒去配置中心查询一次最新的配置信息,不配置此项默认刷新周期为30秒。
+
+### 获取动态属性
+
+​      在配置中心中创建一个`timeout`的配置项,其值设置为`100`,并发布如下图:      
![动态属性timeout](E:\opensource\dynamic 
config\incubator-servicecomb-website\assets\images\config\release_config.png)
+
+​      
代码中可以使用`DynamicPropertyFactory.getInstance().getProperty()`方法来获取具体的配置项值,`getProperty`方法可以根据配置项具体的类型来灵活使用,比如`getIntProperty()`,`getStringProperty()`等。
+
+   ```java
+   public class XXX {
+      public static void main(String[] args) throws Exception {
+        Log4jUtils.init();
+        BeanUtils.init();
+        while (true) {
+          DynamicIntProperty timeout = DynamicPropertyFactory.getInstance().
+            getIntProperty("timeout", -1);
+          System.out.println(timeout);
+          Thread.sleep(3000);
+        }
+      }
+    }
+   ```
+​      Apollo配置中心修改配置项并发布后,经过一个刷新周期后就会打印出最新的`timeout`值。
+
diff --git a/_users/dynamic-config.md b/_users/dynamic-config.md
new file mode 100644
index 0000000..22a678a
--- /dev/null
+++ b/_users/dynamic-config.md
@@ -0,0 +1,104 @@
+---
+title: "Dynamic Configuration"
+lang: en
+ref: customized-tracing
+permalink: /users/dynamic-config/
+excerpt: "Dynamic Configuration"
+last_modified_at: 2018-01-15T15:01:43-04:00
+redirect_from:
+  - /theme-setup/
+---
+
+{% include toc %}
+## Concept Description
+
+Dynamic Configuration makes it possible to update configuration items during 
the life-cycle of the service without re-deploying it. Users have to deploy 
services with those configurations in xml or properties file in traditional way 
and have to redeploy and restart services to update the configurations which 
could be very difficult to maintain and cost lots time. This problem can be 
solved by importing configuration center, all configuration items can be stored 
and maintained by configuration center, services can get latest configuration 
items through a fixed time period thread without redeploying themselves. Java 
Chassis supports Apollo configuration center currently and it\'s easy to extend 
to other kind of configuration centers by implementing provided interfaces.
+
+## Development Example:
+
+### Deploy and start Apollo configuration center
+
+Apollo services can be easily deployed and started step by step following its 
[official 
document](https://github.com/ctripcorp/apollo/wiki/Apollo-Quick-Start-Docker%E9%83%A8%E7%BD%B2),
 You can also do that by following command:
+
+   ```bash
+   git clone https://github.com/lijasonvip/apollo-image-for-servicecomb.git
+   cd apollo-image-for-servicecomb && docker-compose up
+   ```
+When your console shows `Portal started. You can visit http://localhost:8070 
now!` , it means the service is started and ready for use. Visit Apollo 
configuration pages at `http://localhost:8070` in a browser. Please refer to 
[Docker document](https://docs.docker.com/compose/install/) about 
`docker-compose`.
+
+### Configure services and get a token
+
+* ##### Login to Configuration center and create a project
+
+  Visit the address of Apollo configuration portal service , for example: 
`http://192.168.199.1:8070`
+
+  ![登录配置中心](E:\opensource\dynamic 
config\incubator-servicecomb-website\assets\images\config/login.png)
+
+  The default account to login to Apollo configuration center is apollo and 
admin for username and password respectively.
+
+* ##### Create a project
+
+  ![创建项目](E:\opensource\dynamic 
config\incubator-servicecomb-website\assets\images\config\create_project.png)
+
+  There is a demo project named SampleApp, you can create a project for your 
service by click the green icon `+`. The picture below is a example to create a 
project, fill in your application ID and service name and choose the department 
and owner of the project and then submit them.
+
+![项目信息](E:\opensource\dynamic 
config\incubator-servicecomb-website\assets\images\config\create_project2.png)
+
+* ##### Generate a Token
+
+Visit `http://192.168.199.1:8070/open/manage.html` and fill in application ID 
and service name you just created at last step, then choose department and 
owner of the project and click the create button to generate a token. The token 
will be used later in project code.
+
+![生成TOKEN](E:\opensource\dynamic 
config\incubator-servicecomb-website\assets\images\config\token.png)
+
+### Add dependency in pom.xml
+
+```xml
+    <dependency>
+          <groupId>com.netflix.archaius</groupId>
+          <artifactId>archaius-core</artifactId>
+    </dependency>   
+    <dependency>
+          <groupId>io.servicecomb</groupId>
+          <artifactId>config-apollo</artifactId>
+    </dependency>
+```
+### Add configurations in microservice.yaml
+
+   ```yaml
+   cse:
+     config:
+       client:
+       serverUri: http://127.0.0.1:8070
+   apollo:
+     config:
+       serverUri: http://127.0.0.1:8070
+       serviceName: SampleApp
+       env: DEV
+       clusters: default
+       namespace: application
+       token: testtoken
+       refreshInterval: 10
+   ```
+​      Configuration `cse.config.client.serverUri` is the portal address of 
Apollo configuration center just the same as `apollo.config.serverUri`. 
Configurations under `apollo.config` are parameters of the project that users 
created above, including serviceName, env, clusters, namespace, token and 
refreshInterval. Pay attention to `refreshInterval: 10`, it means service will 
fetch latest configuration items every each 10 seconds, default refresh cycle 
is 30 second if no value is configured here.
+
+### Get configurations
+
+​      Creating a configuration item named `timeout` and set its value to 
`100` then release the configuration with some comments. Example as below:   
![动态属性timeout](E:\opensource\dynamic 
config\incubator-servicecomb-website\assets\images\config\release_config.png)
+
+​      You can use`DynamicPropertyFactory.getInstance().getProperty()` to get 
the value of configuration items. 
+
+   ```java
+   public class Demo {
+      public static void main(String[] args) throws Exception {
+        Log4jUtils.init();
+        BeanUtils.init();
+        while (true) {
+          DynamicIntProperty timeout = DynamicPropertyFactory.getInstance().
+            getIntProperty("timeout", -1);
+          System.out.println(timeout);
+          Thread.sleep(3000);
+        }
+      }
+    }
+   ```
+​      When the configuration items are modified and released in Apollo 
configuration center, the example code above will print latest value of 
`timeout` after a refreshing cycle.
diff --git a/assets/images/config/create_project.png 
b/assets/images/config/create_project.png
new file mode 100644
index 0000000..3256249
Binary files /dev/null and b/assets/images/config/create_project.png differ
diff --git a/assets/images/config/create_project2.png 
b/assets/images/config/create_project2.png
new file mode 100644
index 0000000..955d580
Binary files /dev/null and b/assets/images/config/create_project2.png differ
diff --git a/assets/images/config/login.png b/assets/images/config/login.png
new file mode 100644
index 0000000..ddb2270
Binary files /dev/null and b/assets/images/config/login.png differ
diff --git a/assets/images/config/release_config.png 
b/assets/images/config/release_config.png
new file mode 100644
index 0000000..fd632e7
Binary files /dev/null and b/assets/images/config/release_config.png differ
diff --git a/assets/images/config/token.png b/assets/images/config/token.png
new file mode 100644
index 0000000..7c1948f
Binary files /dev/null and b/assets/images/config/token.png differ


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


> Dynamic configuration document for users
> ----------------------------------------
>
>                 Key: SCB-133
>                 URL: https://issues.apache.org/jira/browse/SCB-133
>             Project: Apache ServiceComb
>          Issue Type: Sub-task
>          Components: Java-Chassis
>            Reporter: Bo Li
>            Assignee: Bo Li
>            Priority: Major
>




--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to