创建网关项目(Spring Cloud Gateway)
创建网关项目
加入网关后微服务的架构图
创建项目
POM文件
<properties>
<java.version>1.8</java.version>
<spring-cloud.version>Greenwich.SR3</spring-cloud.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-gateway</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
修改配置文件
将项目目录下的/src/main/resources/application.properties文件重命名为application.yml,properties配置格式和yml配置格式是等效的,而yml配置格式能更好的被配置中心使用,所以我们使用yml配置格式。
测试网关项目
application.yml配置文件内容修改如下:
server:
port: 9000
spring:
cloud:
gateway:
routes:
- id: first_route
uri: https://github.com/sunweisheng
predicates:
- Path=/test
- port:网关服务端口
- routes:路由集合
- id:路由的唯一标示
- uri:路由目标地址
- predicates:路由条件,如果为true则路由到uri
predicates(还有filters)的种类很多请参考Spring Cloud Gateway官网
启动项目测试
访问127.0.0.1:9000/test
源码
Github仓库:https://github.com/sunweisheng/spring-cloud-example
创建网关项目(Spring Cloud Gateway)的更多相关文章
- 微服务网关实战——Spring Cloud Gateway
导读 作为Netflix Zuul的替代者,Spring Cloud Gateway是一款非常实用的微服务网关,在Spring Cloud微服务架构体系中发挥非常大的作用.本文对Spring Clou ...
- .net core下,Ocelot网关与Spring Cloud Gateway网关的对比测试
有感于 myzony 发布的 针对 Ocelot 网关的性能测试 ,并且公司下一步也需要对.net和java的应用做一定的整合,于是对Ocelot网关.Spring Cloud Gateway网关做个 ...
- 网关服务Spring Cloud Gateway(三)
上篇文章介绍了 Gataway 和注册中心的使用,以及 Gataway 中 Filter 的基本使用,这篇文章我们将继续介绍 Filter 的一些常用功能. 修改请求路径的过滤器 StripPrefi ...
- 网关服务Spring Cloud Gateway(二)
上一篇文章服务网关 Spring Cloud GateWay 初级篇,介绍了 Spring Cloud Gateway 的相关术语.技术原理,以及如何快速使用 Spring Cloud Gateway ...
- 最全面的改造Zuul网关为Spring Cloud Gateway(包含Zuul核心实现和Spring Cloud Gateway核心实现)
前言: 最近开发了Zuul网关的实现和Spring Cloud Gateway实现,对比Spring Cloud Gateway发现后者性能好支持场景也丰富.在高并发或者复杂的分布式下,后者限流和自定 ...
- spring Cloud网关之Spring Cloud Gateway
Spring Cloud Gateway是什么?(官网地址:https://cloud.spring.io/spring-cloud-gateway/reference/html/) Spring C ...
- 网关服务Spring Cloud Gateway(一)
Spring 官方最终还是按捺不住推出了自己的网关组件:Spring Cloud Gateway ,相比之前我们使用的 Zuul(1.x) 它有哪些优势呢?Zuul(1.x) 基于 Servlet,使 ...
- api网关揭秘--spring cloud gateway源码解析
要想了解spring cloud gateway的源码,要熟悉spring webflux,我的上篇文章介绍了spring webflux. 1.gateway 和zuul对比 I am the au ...
- Consul集群加入网关服务(Spring Cloud Gateway)
Consul集群加入网关服务 架构示意图 外部的应用或网站通过外部网关服务消费各种服务,内部的生产者本身也可能是消费者,内部消费行为通过内部网关服务消费. 一个内部网关和一个外部网关以及一个Consu ...
随机推荐
- java随机数Math.random()
double random=Math.random();//返回[0,1)随机数 (int)(Math.random()*6)//返回0-5:随机数 (int)(Math.random()*6+1)/ ...
- elasticsearch 深入 —— 地理位置
地理位置 我们拿着纸质地图漫步城市的日子一去不返了.得益于智能手机,我们现在总是可以知道 自己所处的准确位置,也预料到网站会使用这些信息.我想知道从当前位置步行 5 分钟内可到的那些餐馆,对伦敦更大范 ...
- Redis这篇就够了
Redis 简介 Redis 优势 Redis 数据类型 string hash list set Zset 小总结 基本命令 发布订阅 简介 实例 发布订阅常用命令 事务 实例 Redis 事务命令 ...
- JavaWeb(六):会话与状态管理
HTTP协议是一种无状态的协议,WEB服务器本身不能识别出哪些请求是同一个浏览器发出的 ,浏览器的每一次请求都是完全孤立的.即使 HTTP1.1 支持持续连接,但当用户有一段时间没有提交请求,连接也会 ...
- 禁止打开 F12 开发者工具
禁止F12 window.onkeydown = window.onkeyup = window.onkeypress = function (event) { // 判断是否按下F12,F12键码为 ...
- Java Web学习总结(12)Filter过滤器
一,Filter简介 Filter也称之为过滤器,Filter是对客户端访问资源的过滤,符合条件放行,不符合条件不放行,并且可以对目标资源访问前后进行逻辑处理. 二,Filter开发步骤 1)编写一个 ...
- shell脚本学习 (9) 提取开头或结尾的几行
1 提取开头的n行 用head awk或者 sed实现 do.txt sed 1q do.txt awk 'FNR <= 1' do.txt do.txt文件 2 显示行尾的几行 用tail - ...
- 深入理解js——非构造函数的继承
原文来自阮一峰日志(http://www.ruanyifeng.com/blog/2010/05/object-oriented_javascript_inheritance_continued.ht ...
- webpack对脚本和样式的处理
一.对js处理 webpack本身支持js加载也可以用插件. 1.加载要全局使用的插件比如jquery 在页面用cdn方式引用,然后再webpack.config.js里配置.会让jquery成为全局 ...
- 微信小程序相关操作
显示用户基本信息 在微信小程序中,经常会碰到需要展示微信用户的基本信息,如果只是为了显示用户信息,最简单有效的办法是使用open-data,这是微信小程序内置的用于展示微信开放数据的组件,通过改变ty ...