共計 2130 個字符,預計需要花費 6 分鐘才能閱讀完成。
今天丸趣 TV 小編給大家分享一下如何使用阿波羅整合 zuul 實現動態路由的相關知識點,內容詳細,邏輯清晰,相信大部分人都還太了解這方面的知識,所以分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后有所收獲,下面我們一起來了解一下吧。
1、前言
Windows 系統搭建基于攜程 Apollo 配置中心分布式模式,在此基礎上,介紹如何使用阿波羅整合 zuul 實現動態路由。
2、項目搭建 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.2 下載項目
在官方 github 項目中,把項目下載下來 https://github.com/ctripcorp/apollo,導入到 Eclipse 工程中。如下圖
由于官方給出的分布式搭建需要加入很多啟動參數,過于繁瑣,可以考慮 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.3 application.properties 配置寫入到 Apollo 配置中心 2.3.1 application.properties
如下原本是寫在 spring boot 工程中的配置信息,接下來寫入到配置中心中。
spring.application.name=sop-api-gateway
server.port=9999
zuul.ignored-services= *
2.3.2 創建 apollo 項目
這里我已經創建好了,就不做過多演示了。
將信息上傳寫入到配置文件中,然后在把工程中的 application.properties 文件刪除。
2.3.3 新建 app.properties 文件
2.3.4 編寫代碼
application.java 啟動類
@RestController
@EnableZuulProxy
@EnableApolloConfig
@EnableDiscoveryClient
@SpringBootApplication
public class ApiGateWayApp { public static void main(String[] args) { SpringApplication.run(ApiGateWayApp.class, args);
}
}
注意加注解。
然后直接啟動即可。。。。。。。
3、結果如下
訪問 http://127.0.0.1:9999/test163 即可讀取阿波羅頁面配置參數,頁面修改后可刷新所有阿波羅客戶端
以上就是“如何使用阿波羅整合 zuul 實現動態路由”這篇文章的所有內容,感謝各位的閱讀!相信大家閱讀完這篇文章都有很大的收獲,丸趣 TV 小編每天都會為大家更新不同的知識,如果還想學習更多的知識,請關注丸趣 TV 行業資訊頻道。