02.Apollo配置中心整合spring cloud zuul

一、前言

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

二、項目搭建
參考https://gitee.com/owenwangwen/open-capacity-platform項目
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/owenwangwen/open-capacity-platform.git下載

項目組織結構(功能)[端口]
├── 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 工程中的配置信息,接下來寫入到配置中心中。
02.Apollo配置中心整合spring cloud zuul

2.2.2 創建apollo項目
02.Apollo配置中心整合spring cloud zuul
這裏我已經創建好了,就不做過多演示了。
02.Apollo配置中心整合spring cloud zuul
將信息上傳寫入到配置文件中,然後在把工程中的application.properties文件刪除。
2.2.3 新建app.properties文件
02.Apollo配置中心整合spring cloud zuul
2.2.4 application.java啓動類br/>@RestController
@EnableZuulProxy
br/>@EnableApolloConfig
@EnableDiscoveryClient
br/>@SpringBootApplication
public class ApiGateWayApp {

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

}

02.Apollo配置中心整合spring cloud zuul

02.Apollo配置中心整合spring cloud zuul

注意加註解。
然後直接啓動即可。。。。。。。
最後注意一下windows 系統中,這個文件的配置,因爲我是eclipse 所以要寫配置。用idea可以啓動的時候就寫入。
三、結果如下
02.Apollo配置中心整合spring cloud zuul

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章