本文共 2074 字,大约阅读时间需要 6 分钟。
一、前言
携程 Apollo 配置中心 学习笔记, Windows 系统搭建基于携程Apollo配置中心分布式模式, 在此基础上,介绍如何使用阿波罗整合zuul实现动态路由。
二、项目搭建
参考https://gitee.com/owenwangwen/open-capacity-platform项目 2.1创建Spring Boot项目apollo-zuulapollo-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>org.springframework.boot spring-boot-starter-test test org.springframework.boot spring-boot-starter-actuator true org.springframework.cloud spring-cloud-starter-zuul
2.1.1 下载项目
在官方github项目中,把项目下载下来 https://github.com/ctripcorp/apollo,导入到Eclipse工程中。如下图 ![](https://s1.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 工程中的配置信息,接下来写入到配置中心中。2.2.2 创建apollo项目
这里我已经创建好了,就不做过多演示了。将信息上传写入到配置文件中,然后在把工程中的application.properties文件删除。2.2.3 新建app.properties文件2.2.4 application.java启动类public static void main(String[] args) { SpringApplication.run(ApiGateWayApp.class, args);}
}
注意加注解。
然后直接启动即可。。。。。。。最后注意一下windows 系统中,这个文件的配置,因为我是eclipse 所以要写配置。用idea可以启动的时候就写入。三、结果如下转载于:https://blog.51cto.com/13005375/2084388