前言:前面介绍了一款API网关组件zuul,不过发现spring cloud自己开发了一个新网关gateway,貌似要取代zuul,spring官网上也已经没有zuul的组件了(虽然在仓库中可以更新到,但主页上已经没有了),而且zuul1.x的性能据说也一般,所以本章将引入spring cloud原生网关产品。本章继续前面的内容,前情回顾请参考:

Spring Cloud 微服务一:Consul注册中心

Spring Cloud 微服务二:API网关spring cloud zuul

  • Spring cloud gateway概览
  • Spring cloud gateway,Spring Cloud Gateway是由spring官方基于Spring5.0,Spring Boot2.0,Project Reactor等技术开发的网关.该项目提供了一个构建在Spring Ecosystem之上的API网关,旨在提供一种简单而有效的途径来发送API,并向他们提供交叉关注点,例如:安全性,监控/指标和弹性.

  • 集成gateway
    • 在上一个项目的基础上新建一个module,名称api-gateway,pom中添加如下依赖,其中gateway是spring cloud网关组件,consul用于集成注册中心功能

            <dependency>
      <groupId>org.springframework.cloud</groupId>
      <artifactId>spring-cloud-starter-gateway</artifactId>
      </dependency>
      <dependency>
      <groupId>org.springframework.cloud</groupId>
      <artifactId>spring-cloud-starter-consul-discovery</artifactId>
      </dependency>
    • 启动类保持默认即可
      @SpringBootApplication
      public class ApiGatewayApplication {
      public static void main(String[] args) {
      SpringApplication.run(ApiGatewayApplication.class, args);
      }
      }
    • 主要在于配置文件,配置文件中定义了路由规则以及注册中心的相关配置,以下的配置,会将http://localhost:8088下的所有请求重定向到http://localhost:10086
      server:
      port: 8088
      debug: true spring:
      application:
      name: api-gateway
      cloud:
      gateway:
      routes:
      - id: user_route
      uri: http://localhost:10086
      predicates:
      - Path=/*
      consul:
      host: localhost
      port: 8500
      discovery:
      register: false
    • 启动user-service,api-gateway,在浏览器访问:http://localhost:8088/all,显示服务的内容,调用成功!

Spring Cloud 微服务三: API网关Spring cloud gateway的更多相关文章

  1. Spring Cloud 微服务四:熔断器Spring cloud hystrix

    前言:在微服务架构中,一般都是进程间通信,有可能调用链都比较长,当有底层某服务出现问题时,比如宕机,会导致调用方的服务失败,这样就会发生一连串的反映,造成系统资源被阻塞,最终可能造成雪崩.在sprin ...

  2. 微服务&#183;API网关

    阅文时长 | 3.52分钟 字数统计 | 1232字符 主要内容 | 1.什么是API网关 2.微服务中的API网关 3.几种部署策略 『微服务·API网关』 编写人 | SCscHero 编写时间 ...

  3. .net core 微服务之Api网关(Api Gateway)

    原文:.net core 微服务之Api网关(Api Gateway) 微服务网关目录 1. 微服务引子 2.使用Nginx作为api网关 3.自创api网关(重复轮子) 3.1.构建初始化 3.2. ...

  4. SOA与ESB,微服务与API网关

    SOA与ESB,微服务与API网关 SOA: ESB: 微服务: API网关: 参考资料: 1.漫画微服务,http://www.sohu.com/a/221400925_100039689 2.SO ...

  5. 一站式入口服务|爱奇艺微服务平台 API 网关实战 原创 弹性计算团队 爱奇艺技术产品团队

    一站式入口服务|爱奇艺微服务平台 API 网关实战 原创 弹性计算团队 爱奇艺技术产品团队

  6. 【spring colud】spring cloud微服务项目搭建【spring boot2.0】

    spring cloud微服务项目搭建 =================================== 示例版本: 1.spring boot 2.0版本 2.开发工具 IntellJ IDE ...

  7. 利用 Maven 构造 Spring Cloud 微服务架构 模块使用 spring Boot构建

    采用Maven 聚合工程搭建 Spring Cloud 使用工具: IntelliJ IDEA    版本: 2019.2.2 maven             版本: 3.6.0 JDK      ...

  8. 基于spring-cloud的微服务(4)API网关zuul

    API网关是微服务架构中的很重要的一个部分,内部有多个不同的服务提供给外部来使用,API网关可以对外做统一的入口,也可以在网关上做协议转换,权限控制和请求统计和限流等其他的工作 spring-clou ...

  9. Net分布式系统之六:微服务之API网关

    本人建立了个人技术.工作经验的分享微信号,计划后续公众号同步更新分享,比在此更多具体.欢迎有兴趣的同学一起加入相互学习.基于上篇微服务架构分享,今天分享其中一个重要的基础组件“API网关”. 一.引言 ...

随机推荐

  1. linux之rpm指令

    rmp原本是Red Hat Linux发行版专门用来管理Linux各项套件的程序,由于它遵循GPL规则且功能强大方便,因而广受欢迎.逐渐受到其他发行版的采用.RPM套件管理方式的出现,让Linux易于 ...

  2. 【Linux】Linux下 环境变量/etc/profile、/etc/bashrc、~/.bashrc的区别【转】

    转自:http://blog.csdn.net/qiao1245/article/details/44650929 ------------------------------------------ ...

  3. 粗谈CDN

    CDN:内容分发网络(content delivery network) 1.DNS解析到最快(有可能是地理上最近,也有可能是地理上远但是链路最好)的CDN缓存设备 2.从CDN获取已经缓存的资源 3 ...

  4. 关于iframe的高度自适应问题(js)

    function SetCwinHeight() { var cwin=document.getElementById("cwin"); if (document.getEleme ...

  5. Qt中重绘制窗口方法:

    void CircleWidget::paintEvent(QPaintEvent * event) { QPainter painter(this); int wight = this->wi ...

  6. vim+python

    #!/bin/bash # install fisa vim config echo '===============================' echo 'start to install ...

  7. Loadrunner 工作原理图

    1.LoadRunner的总体架构图,从图中可以看出组件VUGen, Controller和Analysis之间的关系. 2.LoadRunner的工作原理,从图中可以看出如何利用LoadRunner ...

  8. mui 本地打包

    第一步:下载HBuilder离线打包Android版SDK 网址:http://ask.dcloud.net.cn/article/38 第二步:导入项目 启动带ADT的eclipse程序,菜单中选择 ...

  9. React Native 爬坑之路

    1.react 基础 (创建组件及在浏览器上渲染组件) <!DOCTYPE html> <html lang="en"> <head> < ...

  10. lodash 数组裁剪 drop

    _.drop(array, [n=1]) 裁剪数组中的前 N 个数组,返回剩余的部分. <!DOCTYPE html> <html lang="zh"> & ...