@Bean public RouteLocator customRouteLocator(RouteLocatorBuilder builder) { return builder.routes() .route(r -> r.path("/myapi/**") .filters(f -> f.requestRateLimiter(c -> c.setRateLimiter(myRateLimiter())) .prefixPath("/downstream")) .uri("http://localhost:"+port)) .build(); }
@Bean public RouteLocator testRouteLocator(RouteLocatorBuilder builder) { return builder.routes() .route("custom_redis_rate_limiter", r -> r.path("/custom") .filters(f -> f.requestRateLimiter() .rateLimiter(RedisRateLimiter.class, rl -> rl.setBurstCapacity(40).setReplenishRate(20)) .and()) .uri("http://localhost")) .route("alt_custom_redis_rate_limiter", r -> r.path("/custom") .filters(f -> f.requestRateLimiter(c -> c.setRateLimiter(myRateLimiter()))) .uri("http://localhost")) .build(); }
@Bean RouteLocator gateway(RouteLocatorBuilder rlb) { return rlb .routes() .route(rSpec -> rSpec .path("/proxy").and().host("*.foo.gw") .filters(fSpec -> fSpec.requestRateLimiter(config -> config .setRateLimiter(this.redisRateLimiter()) .setKeyResolver(new PrincipalNameKeyResolver()) )) .uri("http://localhost:8080/hashtags") ) .build(); }
@Bean public RouteLocator customRouteLocator(RouteLocatorBuilder builder) { //@formatter:off return builder.routes() .route("path_route", r -> r.path("/get") .uri("http://httpbin.org")) .route("host_route", r -> r.host("*.myhost.org") .uri("http://httpbin.org")) .route("rewrite_route", r -> r.host("*.rewrite.org") .filters(f -> f.rewritePath("/foo/(?<segment>.*)", "/${segment}")) .uri("http://httpbin.org")) .route("hystrix_route", r -> r.host("*.hystrix.org") .filters(f -> f.hystrix(c -> c.setName("slowcmd"))) .uri("http://httpbin.org")) .route("hystrix_fallback_route", r -> r.host("*.hystrixfallback.org") .filters(f -> f.hystrix(c -> c.setName("slowcmd").setFallbackUri("forward:/hystrixfallback"))) .uri("http://httpbin.org")) .route("limit_route", r -> r .host("*.limited.org").and().path("/anything/**") .filters(f -> f.requestRateLimiter(c -> c.setRateLimiter(redisRateLimiter()))) .uri("http://httpbin.org")) .route("websocket_route", r -> r.path("/echo") .uri("ws://localhost:9000")) .build(); //@formatter:on }
.route("fortune_api", p -> p.path("/v2/fortune").and().host("api.monolith.com") .filters(f -> f.setPath("/fortune") .requestRateLimiter().rateLimiter(RedisRateLimiter.class, c -> c.setBurstCapacity(1).setReplenishRate(1)) .configure(c -> c.setKeyResolver(exchange -> Mono.just(exchange.getRequest().getHeaders().getFirst("X-Fortune-Key")))))