1. 程式人生 > >阿波羅配置中心實戰

阿波羅配置中心實戰

阿波羅配置中心整合zuul

一、前言

攜程 Apollo 配置中心 學習筆記, Windows 系統搭建基於攜程Apollo配置中心分布式模式, 在此基礎上,介紹如何使用阿波羅整合zuul實現動態路由。

二、項目搭建

2.1創建Spring Boot項目apollo-zuul
apollo-zuul項目用的是Eureka作為服務註冊與發現,因此這裏我加入了Eureka Client的依賴,同時需要加入zuul網關的依賴實現微服務的路由
pom.xml文件加入以下依賴

<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>

<artifactId>spring-cloud-starter-eureka</artifactId>
</dependency>
<dependency>
<groupId>com.ctrip.framework.apollo</groupId>
<artifactId>apollo-client</artifactId>
<version>0.10.0-SNAPSHOT</version>
</dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-actuator</artifactId>
        <scope>true</scope>
    </dependency>
    <dependency>
         <groupId>org.springframework.cloud</groupId>
             <artifactId>spring-cloud-starter-zuul</artifactId>
    </dependency>
</dependencies>

2.1.1 下載項目

在官方github項目中,把項目下載下來  https://github.com/ctripcorp/apollo,導入到Eclipse工程中。如下圖
    ![](http://i2.51cto.com/102?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=)
    由於官方給出的分布式搭建需要加入很多啟動參數,過於繁瑣,可以考慮https://gitee.com/234gdfgsdf/open-capacity-platform/tree/master/apollo-master下載

項目組織結構(功能)[端口]
├── apollo -- 阿波羅配置中心
├ ├── apollo-configservice (提供配置的修改、發布等功能,服務對象是Apollo Portal) [8080]
├ ├── apollo-adminservice (提供配置的讀取、推送等功能,服務對象是Apollo客戶端)[8090]
├ ├── apollo-portal (管理界面) [8070]
├ └── apollo-zuul (阿波羅整合zuul網關)
└── open-eureka-server (服務註冊中心)[1111]

2.2 application.properties 配置寫入到Apollo配置中心
2.2.1 application.properties
如下原本是寫在spring boot 工程中的配置信息,接下來寫入到配置中心中。
技術分享圖片

2.2.2 創建apollo項目
技術分享圖片
這裏我已經創建好了,就不做過多演示了。
技術分享圖片
將信息上傳寫入到配置文件中,然後在把工程中的application.properties文件刪除。
2.2.3 新建app.properties文件

技術分享圖片
2.2.4 application.java啟動類@RestController
br/>@RestController
br/>@EnableApolloConfig
br/>@SpringBootApplication

public static void main(String[] args) {
    SpringApplication.run(ApiGateWayApp.class, args);
}

}
註意加註解。
然後直接啟動即可。。。。。。。
最後註意一下windows 系統中,這個文件的配置,因為我是eclipse 所以要寫配置。用idea可以啟動的時候就寫入。
三、結果如下
技術分享圖片

阿波羅配置中心實戰