spring-cloud / spring-cloud/spring-cloud-gateway

Spring Cloud mvc gateway isn't working with lb and few imports in documentation are not clear/not working.

Open
#3,800 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

waiting-for-triage
Dominant language
Java
Stars
4.9k
Forks
3.5k
Avg merge
20h 57m
Merged PRs (30d)
8

Description

Is your feature request related to a problem? Please describe.
It would be helpful if the Spring Cloud Gateway for mvc documentations would be little clear and support for lb when using Eureka server,
like I use the STS tool, and when I copy pasted the below code from https://docs.spring.io/spring-cloud-gateway/reference/spring-cloud-gateway-server-mvc/java-routes-api.html

import static org.springframework.cloud.gateway.server.mvc.filter.BeforeFilterFunctions.uri;
import static org.springframework.cloud.gateway.server.mvc.handler.GatewayRouterFunctions.route;
import static org.springframework.cloud.gateway.server.mvc.handler.HandlerFunctions.http;

class SimpleGateway {
@Bean
public RouterFunction getRoute() {
return route("simple_route").GET("/get", http())
.before(uri("https://example.org"))
.build();
}
}

IDE is not not able to find the uri, and when I checked in the following BeforeFilterFunctions class, there is no uri().

Describe the solution you'd like
some how from here and there I found the below code working

@Bean
public RouterFunction<ServerResponse> headerEnhancementRoutes() {
    return GatewayRouterFunctions.route("datamanager_ms")
        // Explicitly specify URI for programmatic route
        .route(path("/datamanager/**"), http("lb://DATAMANAGER"))
        .before(addRequestHeader("Authorization", "Bearer testToken"))
        .build()
        .and(
            GatewayRouterFunctions.route("taskmanager_ms")
                .route(path("/taskmanager/**"), http("http://localhost:8000"))
                .before(addRequestHeader("Authorization", "Bearer testToken"))
                .build()
        );
}

but this too have some issue like its working with http only but not the lb, after using

Describe alternatives you've considered
need to use the http() but since I have eureka server configured, will it be ok the use the http, if I can use the lb?

Additional context
Add any other context or screenshots about the feature request here.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Java routes API documentation at the linked page and compare its imports with BeforeFilterFunctions and GatewayRouterFunctions. Reproduce the documented route with the reported Eureka and lb setup, then clarify the valid imports and document or correct the load-balanced route behavior so the examples work as described.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring, spring-boot
Domain
api, backend, documentation
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.