These are chat archives for spring-cloud/spring-cloud

Feb 2019
Maxime Menard
Feb 06 16:20
Hi, I have a spring-cloud-gateway app and I need to do API key validation in this one. The API key is in the "x-api-key" header. Is it better to use Spring Security reactive, or just create a custom filter which will return 401 if API key is incorrect ? Thanks !
Spencer Gibb
Feb 06 16:29
@mmenard-bbc it depends. If it is per route a filter can deal with that since they are scoped to a route, otherwise, spring security applies above gateway
Maxime Menard
Feb 06 16:31
@spencergibb actually if it is a filter, it should be a global filter which should apply for all the routes. So for that scenario, you think spring security is better ?
Spencer Gibb
Feb 06 16:38
Then there's nothing specific to gateway, I'd say yes
Maxime Menard
Feb 06 16:38
@spencergibb Thanks ;)
Anton Fedosov
Feb 06 19:59
How can i use gateway routing with eureka zone?
I want a routing over two zones :( But i dont understand how can i select serviceId by zone in runtime;
Select zone by request params is critical for me;
Small use case:
GET /users
headers: UserId=123
should routed to /users in users-api with zone foo

GET /users
headers: UserId=456
should routed to /users in users-api with zone bar

and application.yml
123: foo
456: bar
RouteDefinitionLocator should have helped me, but he dont access to request for get params and he is configured once;
Spencer Gibb
Feb 06 20:09
@acidelk it is not built in. It's possible, but not easy to do. Mostly because ribbon doesn't expose a way to pass context (ie which zone) from the outside. The spring-cloud-loadbalancer will make this easier in the future since it includes a context.
Archimedes Trajano
Feb 06 22:29
Hi, I am trying to make my own DiscoveryClient
for now I am just trying to hard code values for it to use with Spring-Cloud Gateway
What I am trying to do is something like this
    public RouteLocator customRouteLocator(RouteLocatorBuilder builder) {
        return builder.routes()
            .route("path_route", r -> r.path("/get")
            .route("x", r -> r.path("/config/**")
I had constructed ServiceInstances like this:
           new DefaultServiceInstance(
                "localhost", // should be the service name as well
                8080, false
but when I try to access it using the service ID I noticed in the debug logs I end up with:
Mapping [Exchange: GET http://localhost:8081/config/adsf] to Route{id='CompositeDiscoveryClient_config', uri=lb://config, order=0,$$Lambda$755/0x000000080069b040@2fffdbf7, gatewayFilters=[OrderedGatewayFilter{$$Lambda$757/0x000000080069a840@567bbe5c, order=1}]}
the problem I have is this uri is set to lb://config rather than the expected value of http://localhost:8080
the class starts with
public class DockerSwarmDiscoveryClient implements DiscoveryClient {
so I don't really see anything innocuous.
Archimedes Trajano
Feb 06 22:39
I think I narrowed it down to some urlExpression based on the code
Archimedes Trajano
Feb 06 22:51
Figured it out
urlExpression: "uri"
that got it to work
Archimedes Trajano
Feb 06 23:11
BTW how does DiscoveryClient indicate to the caller that there's new changes?