Hystrix断路器和Ratelimitter不适用于Spring Cloud Gateway

时间:2019-10-07 12:33:03

标签: spring-cloud-netflix hystrix spring-cloud-gateway

我正在使用Spring云网关实现API网关功能。

我的问题很少,请问能解决一下吗?

  1. 当我部署到openshift时,Hystrix Circulator Breaker无法正常工作,因为它在本地运行得很好
  2. 尝试实施Ratelimiter,但无法产生429个请求错误(甚至不是本地错误)
@SpringBootApplication
@EnableDiscoveryClient
public class GatewayServiceApplication {

    public static void main(String[] args) {
        SpringApplication.run(GatewayServiceApplication.class, args);
    }

    @Bean(name = "userKeyResolver")
    public KeyResolver userKeyResolver() {
        return exchange -> {
            return Mono.just(exchange.getRequest().getRemoteAddress().getAddress().getHostAddress());
        };
    }
}

application.yml

 spring:

    cloud:
    gateway:
      routes:
      - id: interface-service
        uri: http://interface-service-env.alpha.prof.comp.com
        predicates:
        - Path=/v1/getConfig
        filters:
        - name: Hystrix
          args:
            name: fallbackcmd
            fallbackUri: forward:/fallback/getConfig
        - RewritePath=/v1/getConfig, /getConfig

      - id: interface-service
        uri: http://interface-service-env.alpha.prof.comp.com
        predicates:
        - Path=/helloworld
        filters:
        - name: RequestRateLimiter
          args:
            redis-rate-limiter.replenishRate: 1
            redis-rate-limiter.burstCapacity: 1
            key-resolver: "#{@userKeyResolver}" 
@RestController
@RequestMapping("/fallback")
public class HysController {

    @GetMapping("/getConfig")
    public String getConfig() {
        return "API Call is down, This is the fall back Service for /getConfig ";
    }
}

0 个答案:

没有答案