gateway整合hystrix踩坑

本文详细记录了在整合gateway与hystrix时遇到的问题,包括配置生效的关键在于hystrix过滤器,线程池模式下并发数限制以及隔离策略默认设置错误等。通过源码分析,找到了解决方案,即明确设置隔离策略为THREAD,从而实现正常压测。
摘要由CSDN通过智能技术生成

问题

gateway整合hystrix,测试熔断功能。

注意事项

  • gateway整合hystrix是否生效和启动类上的注解@EnableHystrix没有什么关系
  • gateway整合hystrix生效的关键是在于是否配置了hystrix的过滤器,配置了全局或路由局部的都可以,我这里配置的全局
spring:
    gateway:
      discovery:
        locator:
          # 开启负载均衡对网关的路由转发的支持
          enabled: true
      enabled: true    
      default-filters:
        # 熔断过滤器
        - name: Hystrix
          args:
            name: fallbackcmd
            fallbackuri: forward:/fallexecute
  • hystrix的依赖,不能去掉,否则会报异常,是因为gateway中route路由组件需hystrix
<!-- 此依赖不能去掉 -->
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
</dependency>
缺失hystrix依赖的报错信息:

Caused by: reactor.core.Exceptions$ErrorCallbackNotImplemented: java.lang.IllegalArgumentException: Unable to find GatewayFilterFactory with name Hystrix
Caused by: java.lang.IllegalArgumentException: Unable to find GatewayFilterFactory with name Hystrix
	at org.springframework.cloud.gateway.route.RouteDefinitionRouteLocator.loadGatewayFilters(RouteDefinitionRouteLocator.java:187) ~[spring-cloud-gateway-server-2.2.9.RELEASE.jar:2.2.9.RELEASE]
	at org.springframework.cloud.gateway.route.RouteDefinitionRouteLocator.getFilters(RouteDefinitionRouteLocator.java:228) ~[spring-cloud-gateway-server-2.2.9.RELEASE.jar:2.2.9.RELEASE]
	at org.springframework.cloud.gateway.route.RouteDefinitionRouteLocator.convertToRoute(RouteDefinitionRouteLocator.java:170) ~[spring-cloud-gateway-server-2.2.9.RELEASE.jar:2.2.9.RELEASE]
	at reactor.core.publisher.FluxMap$MapSubscriber.onNext(FluxMap.java:100) ~[reactor-core-3.3.17.RELEASE.jar:3.3.17.RELEASE]
	at reactor.core.publisher.FluxFlatMap$FlatMapMain.tryEmitScalar(FluxFlatMap.java:481) ~[reactor-core-3.3.17.RELEASE.jar:3.3.17.RELEASE]
......

gateway整合hystrix的两种模式(线程池/信号量)细节问题

配置

spring:
  cloud:
    nacos:
      discovery:
        server-addr: localhost:8848
    gateway:
      discovery:
        locator:
          # 开启负载均衡对网关的路由转发的支持
          enabled: true
      enabled: true    
      default-filters:
        # 熔断过滤器
        - name: Hystrix
          args:
            name: fallbackcmd
            fallbackuri: forward:/fallexecute
      # 负载均衡路由规则 开启路由后的服务swagger才能显示
      routes:
        - id: test-service
          uri: lb://test-service
          predicates:
            - Path=/gateway/test/**
          filters:
            - StripPrefix=2
          
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值