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>
- <dependency>
- 在启动类中添加@EnableZuulProxy注解,启用zuul
- @SpringBootApplication
- @EnableZuulProxy
- public class ApiGatewayApplication {
- public static void main(String[] args) {
- SpringApplication.run(ApiGatewayApplication.class, args);
- }
- }
- @SpringBootApplication
- 修改配置文件application.yml,设置相关路由,url为上一章中consul消费者的地址
- server:
- port: 8080
- spring:
- application:
- name: api-gateway-zuul
- zuul:
- routes:
- user:
- path: /user/**
- url: http://localhost:10080/
- debug: true
- server:
- 分别启动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
- server:
- 重启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 ...
随机推荐
- 【转载】GCC 预处理器选项
预处理器选项(Preprocessor Option) 下列选项针对C预处理器,预处理器用在正式编译以前,对C 源文件进行某种处理. 如果指定了`-E'选项, GCC只进行预处理工作.下面的某些选项必 ...
- Word插入页码简单方法
适用于只有一个首页,若是从某一页,需要分节符,从某一页参考Word2007插入两种页码. 插入-页码-页面低端-弹到设计窗口.然后选择页码-设置页码格式-起始页码0-勾选首页不同.
- The newly created daemon process has a different context than expected
Error: The newly created daemon process has a different context than expected. It won't be possible ...
- 本地启动tomcat的时候报内存溢出错误:java.util.concurrent.ExecutionException: java.lang.OutOfMemoryError: PermGen space
问题分析: PermGen space的全称是Permanent Generation space,是指内存的永久保存区域,这块内存主要是被JVM存放Class和Meta信息的,Class在被Load ...
- zabbix日志监控
一般情况下,日志最先反映出应用当前的问题,在海量日志里面找到我们异常记录,例如监控系统日志.nginx.Apache.业务日志,然后记录下来,并且根据情况报警. 1.日志监控项介绍 最主要的是监控日志 ...
- 2017.4.18 慕课网-spring事务管理总结
1.课程目标 事务回顾 spring中的事务管理的api spring中编程式事务管理 spring中声明式事务管理 2.事务回顾 2.1 事务的概念 事务是指逻辑上的一组操作,要么全成功,要么全失败 ...
- WinSock基本知识
这里不打算系统地介绍socket或者WinSock的知识.首先介绍WinSock API函数,讲解阻塞/非阻塞的概念:然后介绍socket的使用. WinSock API Socket接口是网络编程( ...
- iOS_block代码块
watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcHJlX2VtaW5lbnQ=/font/5a6L5L2T/fontsize/400/fill/I0JBQk ...
- 基于WPF系统框架设计(2)-Fluent Ribbon之HelloWorld
Fluent/Ribbon是微软在其最新桌面操作系统Windows 7中使用的图形用户界面. Windows平台的进化,伴随着系统图形界面的重新设计.从Windows XP到Windows Vista ...
- Windows 用VS编译libevent源码
原理:从github上克隆libevent源码,然后使用cmake生成VS工程 github 上 libevent项目地址:https://github.com/libevent/libevent 第 ...