Spring Cloud 微服务三: API网关Spring cloud gateway
前言:前面介绍了一款API网关组件zuul,不过发现spring cloud自己开发了一个新网关gateway,貌似要取代zuul,spring官网上也已经没有zuul的组件了(虽然在仓库中可以更新到,但主页上已经没有了),而且zuul1.x的性能据说也一般,所以本章将引入spring cloud原生网关产品。本章继续前面的内容,前情回顾请参考:
Spring Cloud 微服务二:API网关spring cloud zuul
- Spring cloud gateway概览
- 集成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,显示服务的内容,调用成功!
- 在上一个项目的基础上新建一个module,名称api-gateway,pom中添加如下依赖,其中gateway是spring cloud网关组件,consul用于集成注册中心功能
Spring cloud gateway,Spring Cloud Gateway是由spring官方基于Spring5.0,Spring Boot2.0,Project Reactor等技术开发的网关.该项目提供了一个构建在Spring Ecosystem之上的API网关,旨在提供一种简单而有效的途径来发送API,并向他们提供交叉关注点,例如:安全性,监控/指标和弹性.
Spring Cloud 微服务三: API网关Spring cloud gateway的更多相关文章
- 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 ...
- 基于spring-cloud的微服务(4)API网关zuul
API网关是微服务架构中的很重要的一个部分,内部有多个不同的服务提供给外部来使用,API网关可以对外做统一的入口,也可以在网关上做协议转换,权限控制和请求统计和限流等其他的工作 spring-clou ...
- Net分布式系统之六:微服务之API网关
本人建立了个人技术.工作经验的分享微信号,计划后续公众号同步更新分享,比在此更多具体.欢迎有兴趣的同学一起加入相互学习.基于上篇微服务架构分享,今天分享其中一个重要的基础组件“API网关”. 一.引言 ...
随机推荐
- Visio中如何让重叠图形都显示
如图,两个矩形重叠部分的边框都显示了,是拆分操作,不是组合.
- Android简单的利用SoundPool进行播放铃声的实例代码
MainActivity.java package com.example.pengdonglin.soundpool_demo; import android.annotation.Suppress ...
- mysql 的常用查询
Ø 基本常用查询 --select select * from student; --all 查询所有 select all sex from student; --distinct 过滤重复 ...
- ES6中的Map集合(与java里类似)
Set类型可以用来处理列表中的值,但是不适用于处理键值对这样的信息结构.ES6也添加了Map集合来解决类似的问题 一.Map集合 JS的对象(Object),本质上是键值对的集合(Hash结构),但是 ...
- 2016.6.20 tomcat端口始终被占用
我在使用tomcat7时,服务开启时,始终提示端口被占用. 但是从进程中又看不到开启的tomcat. 最后在资源监视器中,结束重复开启的tomcat. (注意是资源监视器,刚开始的时候看成管理器,怎么 ...
- ios网络学习------10 原生API文件上传
使用原生态的api上传文件的实现: #import "MainViewController.h" @interface MainViewController () @propert ...
- react native使用 mobx , can't find variable:Symbol
原因是因为 mobx的版本用的最新版本..用到了 Symbol部分es6的api特性. 解决问题办法 1. 把mobx降版本到 4.3.1 . mobx-react降版本到 5.1.0 即可. 或者 ...
- Nginx:管理HTTP模块的配置项
参考资料<深入理解Nginx> 一个nginx.conf的例子 http { mytest_num ; server { server_name A; listen ; mytest_nu ...
- spring mvc controller中的异常封装
http://abc08010051.iteye.com/blog/2031992 一直以来都在用spring mvc做mvc框架,我使用的不是基于注解的,还是使用的基于xml的,在controlle ...
- shell脚本通过ping命令来获取平均延时
#!/bin/bash #设置环境变量 PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin" exp ...