码迷,mamicode.com
首页 > 其他好文 > 详细

阿波罗配置中心实战

时间:2018-03-09 10:39:33      阅读:949      评论:0      收藏:0      [点我收藏+]

标签:阿波罗配置中心整合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启动类br/>@RestController
@EnableZuulProxy
br/>@EnableApolloConfig
@EnableDiscoveryClient
br/>@SpringBootApplication
public class ApiGateWayApp {

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

}
注意加注解。
然后直接启动即可。。。。。。。
最后注意一下windows 系统中,这个文件的配置,因为我是eclipse 所以要写配置。用idea可以启动的时候就写入。
三、结果如下
技术分享图片

阿波罗配置中心实战

标签:阿波罗配置中心整合zuul

原文地址:http://blog.51cto.com/13005375/2084388

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!