Spring Cloud 微服务二:API网关spring cloud zuul
前言:本章将继续上一章Spring Cloud微服务,本章主要内容是API 网关,相关代码将延续上一章,如需了解请参考:Spring Cloud 微服务一:Consul注册中心
- Spring cloud zuul概览
- 集成zuul
- 延续上一个项目,新建module api-gateway-zuul pom中添加zuul的依赖
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-zuul</artifactId>
</dependency> - 在启动类中添加@EnableZuulProxy注解,启用zuul
@SpringBootApplication
@EnableZuulProxy
public class ApiGatewayApplication {
public static void main(String[] args) {
SpringApplication.run(ApiGatewayApplication.class, args);
}
} - 修改配置文件application.yml,设置相关路由,url为上一章中consul消费者的地址
server:
port: 8080
spring:
application:
name: api-gateway-zuul
zuul:
routes:
user:
path: /user/**
url: http://localhost:10080/
debug: true - 分别启动user-service,user-consumer,api-gateway-zuul,访问 http://localhost:8080/user/users, 能够正常返回信息,说明路由已成功
- 服务化,使用url配置路由在微服务场景下非常不方便,为此,zuul支持另外一种配置:使用serviceId
server:
port: 8080
spring:
application:
name: api-gateway-zuul
cloud:
consul:
host: localhost
port: 8500
discovery:
register: false
zuul:
routes:
user:
path: /user/**
serviceId: user-service
debug: true使用serviceId替换url,值为服务提供者Id
- 重启api-gateway-zuul,访问 http://localhost:8080/user/all, 能够正常返回信息,说明路由已成功
- 延续上一个项目,新建module api-gateway-zuul pom中添加zuul的依赖
zuul 是netflix开源的一个API Gateway 服务器, 本质上是一个web servlet应用。Zuul 在云平台上提供动态路由,监控,弹性,安全等边缘服务的框架。Spring对zuul进行了整合,使开发者能够很方便地使用zuul
Spring Cloud 微服务二:API网关spring cloud zuul的更多相关文章
- Spring Cloud 微服务四:熔断器Spring cloud hystrix
前言:在微服务架构中,一般都是进程间通信,有可能调用链都比较长,当有底层某服务出现问题时,比如宕机,会导致调用方的服务失败,这样就会发生一连串的反映,造成系统资源被阻塞,最终可能造成雪崩.在sprin ...
- 微服务·API网关
阅文时长 | 3.52分钟 字数统计 | 1232字符 主要内容 | 1.什么是API网关 2.微服务中的API网关 3.几种部署策略 『微服务·API网关』 编写人 | SCscHero 编写时间 ...
- .net core 微服务之Api网关(Api Gateway)
原文:.net core 微服务之Api网关(Api Gateway) 微服务网关目录 1. 微服务引子 2.使用Nginx作为api网关 3.自创api网关(重复轮子) 3.1.构建初始化 3.2. ...
- SOA与ESB,微服务与API网关
SOA与ESB,微服务与API网关 SOA: ESB: 微服务: API网关: 参考资料: 1.漫画微服务,http://www.sohu.com/a/221400925_100039689 2.SO ...
- 一站式入口服务|爱奇艺微服务平台 API 网关实战 原创 弹性计算团队 爱奇艺技术产品团队
一站式入口服务|爱奇艺微服务平台 API 网关实战 原创 弹性计算团队 爱奇艺技术产品团队
- 【spring colud】spring cloud微服务项目搭建【spring boot2.0】
spring cloud微服务项目搭建 =================================== 示例版本: 1.spring boot 2.0版本 2.开发工具 IntellJ IDE ...
- 利用 Maven 构造 Spring Cloud 微服务架构 模块使用 spring Boot构建
采用Maven 聚合工程搭建 Spring Cloud 使用工具: IntelliJ IDEA 版本: 2019.2.2 maven 版本: 3.6.0 JDK ...
- Net分布式系统之六:微服务之API网关
本人建立了个人技术.工作经验的分享微信号,计划后续公众号同步更新分享,比在此更多具体.欢迎有兴趣的同学一起加入相互学习.基于上篇微服务架构分享,今天分享其中一个重要的基础组件“API网关”. 一.引言 ...
- 基于spring-cloud的微服务(4)API网关zuul
API网关是微服务架构中的很重要的一个部分,内部有多个不同的服务提供给外部来使用,API网关可以对外做统一的入口,也可以在网关上做协议转换,权限控制和请求统计和限流等其他的工作 spring-clou ...
随机推荐
- Linux系统入门命令100条 转
https://www.howtoforge.com/linux-commands/ 2017-04-27 RiboseYim 睿哥杂货铺 Author : Himanshu Arora 原文:htt ...
- DEV MarqueeProgressBarControl控件
原文地址:http://www.dobug.net/showtopic-672.html MarqueeProgressBarControl是DevExpress的一个进度条控件,该控件和Progre ...
- flask调试代码更改、模板更改后立即生效
1.app.DEBUG=True时,代码更改后立即生效 2.APP.jinja_env.auto_reload = True时,模板修改后立即生效,无需重启 参考:https://stackoverf ...
- IE常见BUG总结(持续更新)
ie6~7下display:inline-block无效 解决方案:需要hack触发hasLayout 1 //IE6.7中内联元素(如span)触发layout属性后, 它的行为和标准中的 inli ...
- Jquery.data()的值存放再什么地方的问题?
Where is jQuery.data() stored? Where does jQuery store the values of the data() that it sets to DOM ...
- 编译安装Nginx和php搭建KodExplorer网盘
编译安装Nginx和php搭建KodExplorer网盘 环境说明: 系统版本 CentOS 6.9 x86_64 软件版本 nginx-1.12.2 php ...
- swoole编译安装/数据库连接池/异步mysql客户端
一.编译安装php5.6 0.安装必要软件 http://www.cnblogs.com/itfenqing/p/6055138.html 1.下载php5.6.30 http://php.net/d ...
- Warning: isMounted(...) is deprecated in plain JavaScript React classes.
1.错误提示 警告:isMounted(…)在纯 react.js 类中被弃用. 2.原因解析 出现此错误提示的原因是源代码内有已被React舍弃的代码,但此并不影响程序运行. 在index.js 内 ...
- C++类型转换运算符 static_cast,dynamic_cast,reinterpret_cast,const_cast
类型转换是一种让程序猿可以临时或永久性改变编译器对对象的解释机制.可改变对象解释方式的运算符称为类型转换运算符. 为何须要进行类型转换 通常为了实现使用不同环境的个人和厂商编写的模块可以相互调用和协作 ...
- SQL 根据表获取字段字符串
SQLSERVER查询单个数据表所有字段名组合成的字符串脚本 --SQLSERVER查询单个数据表所有字段名组合成的字符串脚本 --应用场合: 用于生成SQL查询字符串中select 字段名列表1 f ...