Spring Cloud之搭建动态Zuul网关路由转发
传统方式将路由规则配置在配置文件中,如果路由规则发生了改变,需要重启服务器。这时候我们结合上节课内容整合SpringCloud Config分布式配置中心,实现动态路由规则。
将yml的内容粘贴到码云上:
###注册 中心
eureka:
client:
serviceUrl:
defaultZone: http://localhost:8100/eureka/
server: ##api网关端口号
port: 80
###网关名称
spring: ##网关服务名称
application:
name: service-zuul
### 配置网关反向代理
zuul:
routes:
api-member: ##随便写的
### 以 /api-member/访问转发到会员服务 通过别名找
path: /api-member/**
serviceId: app-toov5-member ##别名 如果集群的话 默认整合了ribbon 实现轮训 负载均衡
api-order: ##随便写的
### 以 /api-order/访问转发到订单服务
path: /api-order/**
serviceId: app-toov5-order ##别名

添加到依赖:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
可以实现手动刷新
yml中添加:
###默认服务读取eureka注册服务列表 默认间隔30秒 ###开启所有监控中心接口
management:
endpoints:
web:
exposure:
include: "*"
开启所有监控中心接口
启动类里面添加:
//zuul配置使用config实现实时更新
@RefreshScope
@ConfigurationProperties("zuul")
public ZuulProperties zuulProperties() {
return new ZuulProperties();
}

package com.toov5; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.cloud.netflix.zuul.EnableZuulProxy;
import org.springframework.cloud.netflix.zuul.filters.ZuulProperties; @SpringBootApplication
@EnableEurekaClient
@EnableZuulProxy //开启网关代理
public class AppGateway {
public static void main(String[] args) {
SpringApplication.run(AppGateway.class, args);
}
//zuul配置使用config实现实时更新
@RefreshScope
@ConfigurationProperties("zuul")
public ZuulProperties zuulProperties() {
return new ZuulProperties();
} }
yml
###注册 中心
eureka:
client:
serviceUrl:
defaultZone: http://localhost:8100/eureka/
server: ##api网关端口号
port: 80
###网关名称
spring: ##网关服务名称
application:
name: service-zuul
###网关名称
cloud:
config:
####读取后缀
profile: dev
####读取config-server注册地址
discovery:
service-id: confi ### 配置网关反向代理
#zuul:
# routes:
# api-member: ##随便写的
# ### 以 /api-member/访问转发到会员服务 通过别名找
# path: /api-member/**
# serviceId: app-toov5-member ##别名 如果集群的话 默认整合了ribbon 实现轮训 负载均衡
# api-order: ##随便写的
# ### 以 /api-order/访问转发到订单服务
# path: /api-order/**
# serviceId: app-toov5-order ##别名
启动eureka和configserver
访问:

可以读取到
启动 gateway
然后启动 member
访问:

配置文件是从git读取的,成功!
发生变更后同样需要 post刷新下。
Spring Cloud之搭建动态Zuul网关路由转发的更多相关文章
- 【Spring Cloud学习之四】Zuul网关
环境 eclipse 4.7 jdk 1.8 Spring Boot 1.5.2 Spring Cloud 1.2 一.接口网关接口网关:拦截所有的请求,交由接口网关,然后接口网关进行转发,类似ngi ...
- Spring Cloud 专题之四:Zuul网关
书接上回: SpringCloud专题之一:Eureka Spring Cloud专题之二:OpenFeign Spring Cloud专题之三:Hystrix 经过前面三章对Spring Cloud ...
- Spring cloud架构中利用zuul网关实现灰度发布功能
蓝绿发布.金丝雀发布(灰度发布).AB测试 首先,了解下这几种发布方式的基础概念. 目前常见的发布策略有蓝绿发布.金丝雀发布(灰度发布).AB测试这几种,在国内的开发者中,对这几个概念有独立的理解.蓝 ...
- JeeSite Spring Cloud安装搭建
引言 JeeSite Cloud 具备 JeeSite 4.x 的所有功能,是在 JeeSite 4.x 基础之上,完成的 Spring Cloud 分布式系统套件的整合.它利用 JeeSite 4. ...
- spring boot 2.0.3+spring cloud (Finchley)5、路由网关Spring Cloud Zuul
Zuul作为微服务系统的网关组件,用于构建边界服务,致力于动态路由.过滤.监控.弹性伸缩和安全. 为什么需要Zuul Zuul.Ribbon以及Eureka结合可以实现智能路由和负载均衡的功能:网关将 ...
- spring cloud 2.x版本 Zuul路由网关教程
前言 本文采用Spring cloud本文为2.1.8RELEASE,version=Greenwich.SR3 本文基于前两篇文章eureka-server.eureka-client.eureka ...
- Spring Cloud Alibaba | Nacos动态网关路由
Spring Cloud Alibaba | Gateway基于Nacos动态网关路由 本篇实战所使用Spring有关版本: SpringBoot:2.1.7.RELEASE Spring Cloud ...
- Spring Cloud之Zuul网关路由
前端请求先通过nginx走到zuul网关服务,zuul负责路由转发.请求过滤等网关接入层的功能,默认和ribbon整合实现了负载均衡 比如说你有20个服务,暴露出去,你的调用方,如果要跟20个服务打交 ...
- Spring Cloud 系列之 Netflix Zuul 服务网关
什么是 Zuul Zuul 是从设备和网站到应用程序后端的所有请求的前门.作为边缘服务应用程序,Zuul 旨在实现动态路由,监视,弹性和安全性.Zuul 包含了对请求的路由和过滤两个最主要的功能. Z ...
随机推荐
- React 学习推荐
推荐学习一.React 入门实例教程 作者: 阮一峰 http://www.ruanyifeng.com/blog/2015/03/react.html 瘳雪峰的Javascript教程 ht ...
- spring boot 集成mybatis报错
Caused by: org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of ...
- kafka eagle 使用教程
下载 地址:http://download.smartloli.org/ github:https://github.com/smartloli/kafka-eagle 环境 Windows: 安装J ...
- [译]GLUT教程 - 弹出菜单基础
Lighthouse3d.com >> GLUT Tutorial >> Pop-up Menus >> Popup Menus 弹出菜单也是GLUT的一部分.虽然 ...
- 《TomCat与Java Web开发技术详解》(第二版) 第三章节的学习总结--利用Context元素来自定义web应用的存储位置
在学习完第三章后(第三章提供的web应用是helloaapp,我将其放到了tomcat/webapps中),对Context元素的作用理解不深:但是当进入第四章后,发现第四章提供的源码包中也有一个叫h ...
- Google Code Jam 2014 资格赛:Problem B. Cookie Clicker Alpha
Introduction Cookie Clicker is a Javascript game by Orteil, where players click on a picture of a gi ...
- zookeeper 客户端
http://blog.csdn.net/lzy_lizhiyang/article/details/48518731 http://blueyan.iteye.com/blog/2298276 ht ...
- 【cocos2dx 3.3】口袋空战5 总结与公布
打包好的APK:点击下载
- VirtualBox + CentOS 虚拟机网卡配置
摘要: 要学好Linux,还是得自己搭建虚拟机. VirtualBox比较小巧简单,容易上手.在配合CentOS 6.4使用时,首要的问题就是网卡配置,尤其是使用SSH终端仿真程序(例如SecureC ...
- PHP-Manual的学习----【安装与配置】
2017年6月27日17:59:16 安装与配置 安装前需要考虑的事项 Unix系统下的安装 Mac OS x系统下的安装 windows 系统下的安装 云计算平台上的安 ...