spring cloud:gateway-eureka-filter
Spring Cloud Gateway 的 Filter 的生命周期不像 Zuul 的那么丰富,它只有两个:“pre” 和 “post”。
- PRE: 这种过滤器在请求被路由之前调用。我们可利用这种过滤器实现身份验证、在集群中选择请求的微服务、记录调试信息等。
- POST:这种过滤器在路由到微服务以后执行。这种过滤器可用来为响应添加标准的 HTTP Header、收集统计信息和指标、将响应从微服务发送给客户端等。
Spring Cloud Gateway 的 Filter 分为两种:GatewayFilter 与 GlobalFilter。GlobalFilter 会应用到所有的路由上,而 GatewayFilter 将应用到单个路由或者一个分组的路由上。
Spring Cloud Gateway 内置了9种 GlobalFilter,比如 Netty Routing Filter、LoadBalancerClient Filter、Websocket Routing Filter 等,根据名字即可猜测出这些 Filter 的作者,具体大家可以参考官网内容:Global Filters
利用 GatewayFilter 可以修改请求的 Http 的请求或者响应,或者根据请求或者响应做一些特殊的限制。 更多时候我们会利用 GatewayFilter 做一些具体的路由配置,下面我们做一些简单的介绍。
gateway-eureka-filter
1. File-->new spring starter project
2.add dependency
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-gateway</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
3.Edit application.yml
server:
port:
spring:
application:
name: gateway-server-eureka-filter
cloud:
gateway:
discovery:
locator:
enabled: true
routes:
# forward by serviceID
- id: add_request_parameter_route
uri: lb://producer
# uri: http://localhost:8005/getHello
filters:
- AddRequestParameter=name,wang
predicates:
- Method=GET
- Path=/getHello # forward by address
# - id: add_request_parameter_route
# uri: http://localhost:9000
# filters:
# - AddRequestParameter=foo, bar
# predicates:
# - Method=GET eureka:
client:
service-url:
defaultZone: http://localhost:8761/eureka/
logging:
level:
org.springframework.cloud.gateway: debug
4.program
package com.smile; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient; @SpringBootApplication
@EnableEurekaClient
public class GatewayServerEurekaFilterApplication { public static void main(String[] args) {
SpringApplication.run(GatewayServerEurekaFilterApplication.class, args);
} }
5.Run
http://localhost:8080/getHello
访问结果交替出现
hello wang
hello wang,this is producer 1

spring cloud:gateway-eureka-filter的更多相关文章
- spring cloud gateway之filter篇
转载请标明出处: https://www.fangzhipeng.com 本文出自方志朋的博客 在上一篇文章详细的介绍了Gateway的Predict,Predict决定了请求由哪一个路由处理,在路由 ...
- Spring cloud gateway自定义filter以及负载均衡
自定义全局filter package com.example.demo; import java.nio.charset.StandardCharsets; import org.apache.co ...
- 网关服务Spring Cloud Gateway(二)
上一篇文章服务网关 Spring Cloud GateWay 初级篇,介绍了 Spring Cloud Gateway 的相关术语.技术原理,以及如何快速使用 Spring Cloud Gateway ...
- 跟我学SpringCloud | 第十三篇:Spring Cloud Gateway服务化和过滤器
SpringCloud系列教程 | 第十三篇:Spring Cloud Gateway服务化和过滤器 Springboot: 2.1.6.RELEASE SpringCloud: Greenwich. ...
- 微服务网关实战——Spring Cloud Gateway
导读 作为Netflix Zuul的替代者,Spring Cloud Gateway是一款非常实用的微服务网关,在Spring Cloud微服务架构体系中发挥非常大的作用.本文对Spring Clou ...
- SpringCloud无废话入门05:Spring Cloud Gateway路由、filter、熔断
1.什么是路由网关 截至目前为止的例子中,我们创建了一个service,叫做:HelloService,然后我们把它部署到了两台服务器(即提供了两个provider),然后我们又使用ribbon将其做 ...
- Spring Cloud Gateway(二):Spring Cloud Gateway整合Eureka应用
Spring Cloud Gateway 应用概述 下面的示例启动两个服务:gataway-server 和 user-service 都注册到注册中心 Eureka上,客户端请求后端服务[user- ...
- Spring Cloud Gateway整合Eureka
Spring Cloud Gateway features: Built on Spring Framework 5, Project Reactor and Spring Boot 2.0 Able ...
- Spring Cloud Gateway实战之五:内置filter
欢迎访问我的GitHub https://github.com/zq2599/blog_demos 内容:所有原创文章分类汇总及配套源码,涉及Java.Docker.Kubernetes.DevOPS ...
- 微服务网关 Spring Cloud Gateway
1. 为什么是Spring Cloud Gateway 一句话,Spring Cloud已经放弃Netflix Zuul了.现在Spring Cloud中引用的还是Zuul 1.x版本,而这个版本是 ...
随机推荐
- [UER #1] DZY Loves Graph
题目描述 开始有 \(n\) 个点,现在对这 \(n\) 个点进行了 \(m\) 次操作,对于第 \(i\) 个操作(从 \(1\) 开始编号)有可能的三种情况: \(Add\) a b: 表示在 \ ...
- CF894E Ralph and Mushrooms
题目 一眼题. 缩点然后dp. 注意一下计算一条边经过无限次可以获得多少价值这个东西要用到平方和公式. \(\sum\limits_{i=1}^ni^2=\frac{i(i+1)(2i+1)}6\) ...
- Luogu P1650 田忌赛马
题目 如果我们最大比对面最大大,那么直接用. 如果我们最小比对面最小大,那么直接用. 否则用我们最小去换对面最大. #include<bits/stdc++.h> using namesp ...
- java tomcate 启动后cmd 出现乱码
今天windows 启动tomcat 后,出现cmd 乱码 尝试改cmd编码为UTF-8后无效,修改tomcat 注册表CodePage ,cmd 依然乱码, 后来把Conf 目录下的logging. ...
- 7.利用canvas和js画一个渐变的
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...
- 学习-Pytest(五)yield操作
1.fixture的teardown操作并不是独立的函数,用yield关键字呼唤teardown操作 2.scope="module" 1.fixture参数scope=”modu ...
- The Python Challenge 闯关笔记
The Python Challenge : http://www.pythonchallenge.com/ Level 0: 看提示图片中为2**38,计算值为274877906944. Hint: ...
- RSA前端加密
昨天做了登陆模块,接触了md5&RSA加密.有点意思,talk is cheap,show me the code! 前端加密 为什么要加密 前端加密的方式 后台如何解密 1 为什么要加密? ...
- 如何给自己的Python项目制作安装包
Packaging Python Projects¶ 本教程将指导您如何打包一个简单的Python项目.它将向您展示如何添加必要的文件和结构来创建包,如何构建包以及如何将其上载到Python包索引. ...
- git概述(一)
初始化一个Git仓库,使用git init命令. 添加文件到Git仓库,分两步: 使用命令git add <file>,注意,可反复多次使用,添加多个文件: 使用命令git commit ...