Skip to content

Gateway MVC: Service discovery with http prefix only works if RestClient.Builder is declared as a bean (which breaks lb:// routings) #3168

Open
@ah1508

Description

@ah1508

using http:// instead of lb:// for the uri property of routes definition only works if a RestClient.Builder is declared as bean:

@LoadBalanced
@Bean
RestClient.Builder restClientBuilder() {
    return RestClient.builder();
}

RestClient.Builder bean is also required for this code:

@Bean
RouterFunction<ServerResponse> getRoute() {
    return route().GET("/foo/**", http("http://foo-api"));
}

But with a RestClient.Builder bean, lb:// prefix in yml routing configuration does not work (error 500).

If http:// is the way to go @Bean @LoadBalanced RestClient.Builder could be provided by auto configuration (or documented as mandatory) and this page https://docs.spring.io/spring-cloud-gateway/reference/spring-cloud-gateway-server-mvc/filters/loadbalancer.html#_using_the_loadbalancer_filter_in_configuration should not mention lb:// prefix

Maybe I am wrong but it looks like "RouterFunction with http("...") only works if a @LoadBalancer @Bean RestClient.Builder exists and then lb: prefix should not be used". I don't know if it is a bug or if it should be documented but it is not obvious.

With the webflux version a @LoadBalanced WebClient.Builder bean does not break lb:// routings.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions