前言:前面介绍了一款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. 【MySQL性能优化】MySQL常见SQL错误用法

    https://yq.aliyun.com/articles/72501?utm_content=m_14899

  2. delphi 读取编译的version信息

    在create中调用就可以了 unit About; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, ...

  3. androd 获得wifi列表

    AndroidManifest.xml <?xml version="1.0" encoding="utf-8"?> <manifest xm ...

  4. 【spring boot】【mybatis】spring boot中mybatis打印sql语句

    spring boot中mybatis打印sql语句,怎么打印出来?[参考:https://www.cnblogs.com/sxdcgaq8080/p/9100178.html] 在applicati ...

  5. 【XStream】xml和java实体的相互转化

    1.pom.xml <!-- xstream xml和Java对象转化 --> <dependency> <groupId>xstream</groupId& ...

  6. 区别dependencies、devDependencies

    我们在使用npm install 安装模块或插件的时候,有两种命令把他们写入到 package.json 文件里面去,他们是: --save-dev 或 --save 首先需要说明的是Dependen ...

  7. JAVA之抽象类与抽象方法

    抽象方法:在类中没有方法体的方法,就是抽象方法.抽象类:含有抽象方法的类就叫抽象类.|||||||||抽象类不能被实例化(new)为什么要使用抽象方法?(以下是个人观点)因 为在面向对象的编程的思想中 ...

  8. 把e.printStackTrace的堆栈信息打印在log.error()中

    不要这样写: log.error(e);这样只是简单的记录下错误的类型,不能精确出错误出错在哪行 要写成:log.error(e.toString(),e);

  9. elasticsearch 插入数据

    1.单条插入(推荐设定主键id防止重复) public static String addIndex(String index,String type,HashMap<String, Objec ...

  10. 《深入理解Android 卷III》第七章 深入理解SystemUI

    <深入理解Android 卷III>即将公布,作者是张大伟.此书填补了深入理解Android Framework卷中的一个主要空白,即Android Framework中和UI相关的部分. ...