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

6th
Feb 2019
Maxime Menard
@mmenard-bbc
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
@spencergibb
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
@mmenard-bbc
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
@spencergibb
Feb 06 16:38
Then there's nothing specific to gateway, I'd say yes
Maxime Menard
@mmenard-bbc
Feb 06 16:38
@spencergibb Thanks ;)
Anton Fedosov
@acidelk
Feb 06 19:59
Hi!
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
users:
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
@spencergibb
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
@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
    @Bean
    public RouteLocator customRouteLocator(RouteLocatorBuilder builder) {
        return builder.routes()
            .route("path_route", r -> r.path("/get")
                .uri("http://httpbin.org"))
            .route("x", r -> r.path("/config/**")
                .filters(f->f.stripPrefix(1))
                .uri("http://localhost:8080"))
            .build();
    }
I had constructed ServiceInstances like this:
           new DefaultServiceInstance(
                "configButWillEventuallyBeTheDockerServiceID2",
                "config",
                "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, predicate=org.springframework.cloud.gateway.support.ServerWebExchangeUtils$$Lambda$755/0x000000080069b040@2fffdbf7, gatewayFilters=[OrderedGatewayFilter{delegate=org.springframework.cloud.gateway.filter.factory.RewritePathGatewayFilterFactory$$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
@Component
@Slf4j
public class DockerSwarmDiscoveryClient implements DiscoveryClient {
so I don't really see anything innocuous.
Archimedes Trajano
@trajano
Feb 06 22:39
I think I narrowed it down to some urlExpression based on the code
Archimedes Trajano
@trajano
Feb 06 22:51
Figured it out
urlExpression: "uri"
that got it to work
Archimedes Trajano
@trajano
Feb 06 23:11
BTW how does DiscoveryClient indicate to the caller that there's new changes?