springcloud gateway(hystrix filter)
参考
https://blog.csdn.net/forezp/article/details/83792388
1.依赖pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.guo</groupId>
<artifactId>guo</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>guo-gateway</artifactId> <dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-gateway</artifactId>
</dependency>
</dependencies>
</project>
2.配置application.yml
server:
port: 8081 spring:
application:
name: guo-gateway
cloud:
gateway:
discovery:
locator:
enabled: false
lowerCaseServiceId: true eureka:
client:
service-url:
defaultZone: http://localhost:8761/eureka/ logging:
level:
org.springframework.cloud.gateway: debug
3.启动配置
package com.guo.gateway; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.gateway.route.RouteLocator;
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.context.annotation.Bean; @SpringBootApplication
@EnableEurekaClient
public class Application { public static void main(String[] args) {
SpringApplication.run( Application.class, args );
} @Bean
public RouteLocator myRoutes(RouteLocatorBuilder builder) {
String httpUri = "http://localhost:8762/hi";
return builder.routes()
.route(p -> p
.path("/demo")
.filters(f -> f.addRequestHeader("Hello", "World"))
.uri(httpUri))
.build();
}
}
4.启动演示
启动eureka-server eureka-client gateway
访问gateway接口 http://localhost:8081/demo?name=zs 会自动转发到 http://localhost:8762/hi

5.添加熔断器
pom.xml
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
</dependency>
添加过滤器
package com.guo.gateway; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.gateway.route.RouteLocator;
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.context.annotation.Bean;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import reactor.core.publisher.Mono; @SpringBootApplication
@EnableEurekaClient
@RestController
public class Application { public static void main(String[] args) {
SpringApplication.run( Application.class, args );
} @Bean
public RouteLocator myRoutes(RouteLocatorBuilder builder) {
String httpUri = "http://localhost:8762/hi";
return builder.routes()
.route(p -> p
.path("/demo")
.filters(f -> f.addRequestHeader("Hello", "World"))
.uri(httpUri))
.route(p -> p
.path("/hystrix")
.filters(f -> f
.hystrix(config -> config
.setName("mycmd")
.setFallbackUri("forward:/fallback")))
.uri(httpUri))
.build();
} @RequestMapping("/fallback")
public Mono<String> fallback() {
return Mono.just("fallback");
} }

停掉 http://localhost:8762/hi 服务,访问熔断成功。
springcloud gateway(hystrix filter)的更多相关文章
- 使用springcloud gateway搭建网关(分流,限流,熔断)
Spring Cloud Gateway Spring Cloud Gateway 是 Spring Cloud 的一个全新项目,该项目是基于 Spring 5.0,Spring Boot 2.0 和 ...
- SpringCloud gateway (史上最全)
疯狂创客圈 Java 分布式聊天室[ 亿级流量]实战系列之 -25[ 博客园 总入口 ] 前言 ### 前言 疯狂创客圈(笔者尼恩创建的高并发研习社群)Springcloud 高并发系列文章,将为大家 ...
- 基于springcloud gateway + nacos实现灰度发布(reactive版)
什么是灰度发布? 灰度发布(又名金丝雀发布)是指在黑与白之间,能够平滑过渡的一种发布方式.在其上可以进行A/B testing,即让一部分用户继续用产品特性A,一部分用户开始用产品特性B,如果用户对B ...
- SpringCloud gateway 3
参考博客:https://www.cnblogs.com/crazymakercircle/p/11704077.html 1.1 SpringCloud Gateway 简介 SpringCloud ...
- SpringCloud Gateway高阶之Sentinel限流、熔断
前言 为什么需要服务熔断和降级?微服务是当前业界的一大趋势,原理就是将单一职责的功能模块独立化为子服务,降低服务间的耦合,服务间互相调用.但是这样也会出现一些问题: 上图中大量微服务互相调用,存在大量 ...
- SpringCloud Gateway快速入门
SpringCloud Gateway cloud笔记第一部分 cloud笔记第二部分Hystrix 文章目录 SpringCloud Gateway Zull的工作模式与Gateway的对比 Rou ...
- 万字长文:SpringCloud gateway入门学习&实践
官方文档:https://cloud.spring.io/spring-cloud-static/spring-cloud-gateway/2.2.1.RELEASE/reference/html/# ...
- SpringCloud Gateway 测试问题解决
本文针对于测试环境SpringCloud Gateway问题解决. 1.背景介绍 本文遇到的问题都是在测试环境真正遇到的问题,不一定试用于所有人,仅做一次记录,便于遇到同样问题的干掉这些问题. 使用版 ...
- springcloud gateway nullpointerexception (NettyRoutingFilter)
最近在做一个下载功能时,发现直接调用服务是可以下载的,但是通过gateway路由下载会报NPE异常,具体如下 java.lang.NullPointerException: null at java. ...
随机推荐
- 6.6 rsync:文件同步工具
rsync 是一款开源的.快速的.多功能的.可实现全量及增量的本地或远程数据镜像同步备份的优秀工具.rsync适用于Unix/Linux/Windows等多种操作系统平台. rsync命令有三种常 ...
- unity 使用OnDrag实现物体旋转
通过监听UGUI的OnDrag事件 实现对3D物体的旋转 实现IDragHandler接口 void IDragHandler.OnDrag(PointerEventData eventData) { ...
- [leetcode] 44. 通配符匹配(Java)(动态规划)
44. 通配符匹配 动态规划 做动态规划很简单,三步走: 第一步,判断可否用动态规划做,即判断是否满足两个条件:①最优子结构,②重叠子问题.显然该题求s与p是否match,可由其字串层层分解上来. 我 ...
- [leetcode] (周赛)868. 二进制间距
868. 二进制间距 读懂题意就出来了 class Solution { public int binaryGap(int N) { String s = Integer.toBinaryString ...
- 并发编程-Condition
Condition 一个Lock中应该绑定一个Condition对象.Condition是Java提供用来实现等待/通知的类. 我们知道Object对象提供了wait.waitAll.notify.n ...
- TVM性能评估分析(五)
TVM性能评估分析(五) Figure 3. A futher speed up with operator fusion Table 1. Performance issue of cuBLAS ...
- 细粒度语义分割:ICCV2019论文解析
细粒度语义分割:ICCV2019论文解析 Fine-Grained Segmentation Networks: Self-Supervised Segmentation for Improved L ...
- MySQL泛泛而谈(3W字)
下面对于MySQL进行相关介绍,文档的内容较为基础,仅仅设计操作,少量原理,大佬请绕道哦. 废话少说,开冲! 一.MySQL架构介绍 1-MySQL简介 概述 MySQL是一个关系型数据库管理系统,由 ...
- JVM集合之开篇点题
大家在平时的开发过程中是否遇到过StackOverflowError.OutOfMemoryError等类似的内存溢出错误呢?大家又是怎么解决这个问题的?再来,大家在面试过程中有没有被面试官提问过jv ...
- Nginx 配置文件介绍
目录 1.1 常用命令 1.2 Nginx的配置文件结构 1.3 Nginx的全局配置 1.4 HTTP服务器配置 1.5 HttpGzip配置 1.6 负载均衡配置 1.7 server虚拟主机配置 ...