Apollo Configuration Center-api mode and Java mode test

Source: Internet
Author: User

[TOC]

This section to demonstrate
    • Create a project and add the test key value: timeout=8000, batch=9000
    • Use the API to get configuration information by providing a token way
    • Create a Spring boot project, introduce the Apollo rack package, read the configuration
    • See if the Java project is updating the configuration in real time by changing the configuration file
Create a Apollo Project
    1. Click Add Item
    2. Enter project information, note that the app ID is followed by a unique identity that is read by the app
    3. Choose Dev Environment, new configuration, I have tested here, so the dev environment has a gzywtest-c1 cluster, by default, the click Environment is to choose the default configuration

    4. Click Publish so that the configuration information for the dev environment takes effect, and then a token test is generated

Testing interfaces with the Apollo API
    1. Click Administrator Tools-Development Platform licensing management

    1. Enter the necessary information, click Create, Generate tokens

  1. Get all namespace information interfaces under the cluster
    ···
    Curl-h ' Authorization:ab5a901872858535afb48f4da1f7c1c5be522de5 ' \
    -h ' content-type:application/json;charset=utf-8 ' \
    Http://192.168.1.1:8080/openapi/v1/envs/dev/apps/900001/clusters/default/namespaces/application
    ···
    The returned results are as follows
    {"AppId": "900001", "clustername": "Default", "NamespaceName": "Application", "comment": "Default App Namespace", " Format ":" Properties "," IsPublic ": false," items ": [{" Key ":" Redis_host "," Value ":" 127.0.0.1 "," Datachangecreatedby ":" Apollo "," Datachangelastmodifiedby ":" Apollo "," Datachangecreatedtime ":" 2018-07-04t16:55:54.000+0800 "," Datachangelastmodifiedtime ":" 2018-07-04t16:55:54.000+0800 "}, {" Key ":" Timeout "," value ":" 8000 "," comment ":" "," Datachangecreatedby ":" Apollo "," Datachangelastmodifiedby ":" Apollo "," Datachangecreatedtime ":" 2018-07-09t11:0 7:24.000+0800 "," Datachangelastmodifiedtime ":" 2018-07-09t11:13:36.000+0800 "}, {" Key ":" Batch "," Value ":" 9000 "," Comment ":", "Datachangecreatedby": "Apollo", "Datachangelastmodifiedby": "Apollo", "Datachangecreatedtime": " 2018-07-09t11:20:02.000+0800 "," Datachangelastmodifiedtime ":" 2018-07-09t15:38:02.000+0800 "}]," Datachangecreatedby ":" Apollo "," Datachangelastmodifiedby ":" Apollo "," Datachangecreatedtime ":" 2018-07-04t16 : 11:00.000+0800 "," DatachangelasTmodifiedtime ":" 2018-07-04t16:11:00.000+0800 "} 
* Structure URL parameter rules are as follows:! [] (http://i2.51cto.com/images/blog/201807/13/b33c8b06860ad718981228618a33138f.jpg?x-oss-process=image/ watermark,size_16,text_qduxq1rp5y2a5a6i,color_ffffff,t_100,g_se,x_10,y_10,shadow_90,type_zmfuz3pozw5nagvpdgk=) * API for more documentation reference, refer to https://github.com/ctripcorp/apollo/wiki/Apollo%E5%BC%80%E6%94%BE%E5%B9%B3%E5%8F%B0---# # # How to access Java * Reference https://github.com/ctripcorp/apollo/wiki/Java%E5%AE%A2%E6%88%B7%E7%AB%AF%E4%BD%BF%E7%94%A8%E6%8C% 87%e5%8d%97 in fact, the official source package already contains a Apollo-demo project, if you look at the previous deployment of the Apollo project, you should remember that the script finally has a upload local rack package to maven step, this is if you want to do Java build necessary operation, You need to upload the compiled package to a private source.   Because I really did not transfer the official demo project, so according to the official demo project to create a new project to debug, briefly describe the implementation of the Code, followed by the download 1. Open http://start.spring.io/, enter a simple option, click on Build project and download to local! [] (http://i2.51cto.com/images/blog/201807/13/79fe86478a3f2a122ebd541f9d395e0b.jpg?x-oss-process=image/ watermark,size_16,text_qduxq1rp5y2a5a6i,color_ffffff,t_100,g_se,x_10,y_10,shadow_90,type_zmfuz3pozw5nagvpdgk=) 1. Introduce Eclipse! [] (http://i2.51cto.com/images/blog/201807/13/1e63406fb89585f1625fbfb94bf732d9.jpG?x-oss-process=image/watermark,size_16,text_qduxq1rp5y2a5a6i,color_ffffff,t_100,g_se,x_10,y_10,shadow_90,type _zmfuz3pozw5nagvpdgk=) * I have introduced here, so can not be introduced, the normal input directory, after the Eclipse scan click Finish can be introduced! [] (http://i2.51cto.com/images/blog/201807/13/a5c9912039dba831f7684776a6dadae5.jpg?x-oss-process=image/ watermark,size_16,text_qduxq1rp5y2a5a6i,color_ffffff,t_100,g_se,x_10,y_10,shadow_90,type_zmfuz3pozw5nagvpdgk=) 1. In Pom.xml, add the following package ' xml<!--introduced package #####################--<dependency> <groupid>com. Ctrip.framework.apollo</groupid> <artifactId>apollo-client</artifactId> <versio n>0.11.0-snapshot</version> </dependency> <dependency> <groupid>com.ct Rip.framework.apollo</groupid> <artifactId>apollo-core</artifactId> <version&gt ;0.11.0-snapshot</version> </dependency> <dependency> <groupid>coM.google.guava</groupid> <artifactId>guava</artifactId> <version>25.1-jre&lt        ;/version> </dependency> <!--https://mvnrepository.com/artifact/com.google.inject/guice-- <dependency> <groupId>com.google.inject</groupId> &LT;ARTIFACTID&GT;GUICE&L            t;/artifactid> <version>4.2.0</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactid>spring-boot-configuration-pro cessor</artifactid> <optional>true</optional> </dependency> <dependenc        Y> <groupId>com.google.code.gson</groupId> <artifactId>gson</artifactId> </dependency>
    1. The official Apollo-demo under the Com.ctrip.framework.apollo.demo copy to our demo, here only to test the official recommended Java read mode, delete redundant files, the final structure is as follows

    2. Add a running environment selection, here with the dev environment
      #我的是window下测试,所以在
    3. C:\opt\settings\server.properties Add Content: Env=dev
    4. Create a app.properties file in Eclipse's Meta-inf directory add content: app.id=900001

    5. Right-click on Pom.xml on the Run-maven install, then annotationapplication right-click run-spring boot App

    1. The output of the run should be visible as follows

      * 在console回车会看到

Update the configuration to test whether the configuration is updated in real time
    1. Changing the timeout value of the dev environment from the portal into 3000
    2. Release configuration

    3. You can see that the timeout has changed the value in the console output.

      • For more Java access tutorials, refer to https://github.com/ctripcorp/apollo/wiki/Java%E5%AE%A2%E6%88%B7%E7%AB%AF%E4%BD%BF%E7%94%A8%E6%8C%87%E5%8D%97

Apollo Configuration Center-api mode and Java mode test

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.