我正在使用Spring云网关实现API网关功能。
我的问题很少,请问能解决一下吗?
@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 ";
}
}