Fork me on GitHub
阿波罗实战网关

阿波罗实战网关

https://my.oschina.net/JavaLaw/blog/1641498

1、前言
携程 Apollo 配置中心 学习笔记, Windows 系统搭建基于携程Apollo配置中心分布式模式, 在此基础上,介绍如何使用阿波罗整合zuul实现动态路由。

2、项目搭建
2.1 创建Spring Boot项目apollo-zuul
apollo-zuul项目用的是Eureka作为服务注册与发现,因此这里我加入了Eureka Client的依赖,同时需要加入zuul网关的依赖实现微服务的路由

    pom.xml文件加入以下依赖
org.springframework.cloud spring-cloud-starter-eureka com.ctrip.framework.apollo apollo-client 0.10.0-SNAPSHOT
<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>

2.2 下载项目

在官方github项目中,把项目下载下来 https://github.com/ctripcorp/apollo,导入到Eclipse工程中。如下图
img1
由于官方给出的分布式搭建需要加入很多启动参数,过于繁琐,可以考虑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项目

img
这里我已经创建好了,就不做过多演示了。
img
将信息上传写入到配置文件中,然后在把工程中的application.properties文件删除。
2.3.3 新建app.properties文件
img
2.3.4 编写代码
img
img

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即可读取阿波罗页面配置参数,页面修改后可刷新所有阿波罗客户端

posted on 2018-08-03 14:49  HackerVirus  阅读(892)  评论(0)    收藏  举报