@Bean public RouteLocator myRoutes(RouteLocatorBuilder builder) { String httpUri = "http://httpbin.org:80"; return builder.routes() .route(p -> p .path("/get") .filters(f -> f.addRequestHeader("Hello", "World")) .uri(httpUri)) .route(p -> p .host("*.hystrix.com") .filters(f -> f .hystrix(config -> config .setName("mycmd") .setFallbackUri("forward:/fallback"))) .uri(httpUri)) .build(); } // end::route-locator[]
@Bean public RouteLocator hystrixRouteLocator(RouteLocatorBuilder builder) { return builder.routes() .route("hystrix_java", r -> r.host("**.hystrixjava.org") .filters(f -> f.prefixPath("/httpbin") .hystrix(config -> config.setFallbackUri("forward:/fallbackcontroller2"))) .uri(uri)) .route("hystrix_connection_failure", r -> r.host("**.hystrixconnectfail.org") .filters(f -> f.prefixPath("/httpbin") .hystrix(config -> { })) .uri("lb:badservice")) /* * This is a route encapsulated in a hystrix command that is ready to wait * for a response far longer than the underpinning WebClient would. */ .route("hystrix_response_stall", r -> r.host("**.hystrixresponsestall.org") .filters(f -> f.prefixPath("/httpbin") .hystrix(config -> config.setName("stalling-command"))) .uri(uri)) .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_rewrite", p -> p.path("/service/randomfortune") .filters(f -> f.setPath("/fortune") .hystrix(c -> c.setFallbackUri("forward:/defaultfortune"))) .uri("lb://fortune")) .route("hello_rewrite", p -> p.path("/service/hello/**")