Spring Cloud Gateway: Fluent Java Routes API (fluent Java routing API)

Fluent Java Routes API (fluent Java routing API) is a programming method provided by Spring Cloud Gateway for defining routing rules through Java code. It provides an intuitive and easy-to-use way to create and configure routes.

Using the Fluent Java Routes API, you can use chained method calls to build route definitions. Here is an example that demonstrates how to create a simple routing rule using the Fluent API:

@Bean
public RouteLocator customRouteLocator(RouteLocatorBuilder builder, ThrottleGatewayFilterFactory throttle) {
    return builder.routes()
            .route(r -> r.host("**.abc.org").and().path("/image/png")
                .filters(f ->
                        f.addResponseHeader("X-TestHeader", "foobar"))
                .uri("http://httpbin.org:80")
            )
            .route(r -> r.path("/image/webp")
                .filters(f ->
                        f.addResponseHeader("X-AnotherHeader", "baz"))
                .uri("http://httpbin.org:80")
                .metadata("key", "value")
    

Guess you like

Origin blog.csdn.net/qq_29901385/article/details/131325977