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

7th
Feb 2019
Spencer Gibb
@spencergibb
Feb 07 00:14
each call to DiscoveryClient should give the latest values
Archimedes Trajano
@trajano
Feb 07 01:16
Right but how does Spring CLoud Gateway know when to call it again?
What I want is something that would listen to /var/run/docker.sock for server side events and then make it reload when there is a new event.
Jonatan Ivanov
@jonatan-ivanov
Feb 07 05:01

Hi,

I have a service in AWS wich creates a .json file in S3. I would like to consume this in another service and I thought using @ConfigurationProperties would be a convenient way to deserialize (and refresh + validate) it if I can have the file as a PropertySource.

  • Do you happen to know if there is an exsisting solution for this so that I don't need to write a custom PropertySourceLocator for S3?
  • Do you have any other idea for this type of problem?
    • a service produces some data infrequently
    • the data must be kept somewhere and the history is important too
    • another service consumes the data and it should do it in a few minutes after the data was published
Archimedes Trajano
@trajano
Feb 07 05:27
Anyway I found out the answer to my last question regarding the programmatic refresh of gateway
    @Autowired
    private ApplicationEventPublisher publisher;
...
        publisher.publishEvent(new RefreshRoutesEvent(this));
@jonatan-ivanov for yours you can watch an event stream from Amazon (I think you can use SNS, but I never tried it) that would trigger a reload. In my case I plan to use the docker events and the WebClient to listen to SSE to determine if I should refresh my route cache.
Wes
@ezzwes_twitter
Feb 07 07:31
Hi, what’s the difference between using Netflix Spectator through the spring-cloud dependency and the Netflix Spectator API?
Spencer Gibb
@spencergibb
Feb 07 14:56
@trajano you would need to trigger a refresh /actuator/gateway/refresh
haha, I didn't read all the way thru
@jonatan-ivanov I don't know of one. There is one for the aws config service (can't remember name).
Brian Devins-Suresh
@devinsba
Feb 07 14:59
@jonatan-ivanov maybe https://github.com/Netflix/hollow does what you need. The learning curve is quite high but it handles the updates for you once you configure it
Jonatan Ivanov
@jonatan-ivanov
Feb 07 22:00

Thanks all, Hollow seems pretty interesting :)

Could you please point me to the right direction with a related question?
I'm looking for the way (using a PropertySourceLocator) to point spring-boot to a directory which contains the files I downloaded from S3 and I would like to apply the same mechanism what spring does when it loads the properties from the classpath (.yml + .properties+ .json, profiles).

Marcos Barbero
@marcosbarbero
Feb 07 22:05
Maybe you can take a look at configserver code and it may give you some insights?
Archimedes Trajano
@trajano
Feb 07 22:18
For Gateway I am trying to mutate the request header before it goes down the chain and add it to the response coming back.

I tried doing this...

        final ServerHttpRequest request = exchange.getRequest().mutate()
            .header(X_REQUEST_ID, requestID)
            .build();

        ServerWebExchange build = exchange.mutate().request(request).build();
        return chain.filter(build);

but my downstream service does not see the request ID

Spencer Gibb
@spencergibb
Feb 07 22:20
@trajano that's what our standard filter does. Maybe it's an ordering thing? Needs to happen before request is sent.
Archimedes Trajano
@trajano
Feb 07 22:23
This is my annotations
@Slf4j
@Order(-10)
public class RequestIDPreFilter implements GlobalFilter {
@spencergibb our == spring-cloud or our == your own project?
Spencer Gibb
@spencergibb
Feb 07 22:23
spring cloud
Archimedes Trajano
@trajano
Feb 07 22:24
Maybe I am just doing it wrong, the downstream service I am using is httpbin.org
@Bean
public RouteLocator customRouteLocator(RouteLocatorBuilder builder) {
return builder.routes()
.route("path_route", r -> r.path("/get")
.uri("http://httpbin.org"))
.build();
}
Spencer Gibb
@spencergibb
Feb 07 22:25
That should be good enough. Is it a @Bean?
Archimedes Trajano
@trajano
Feb 07 22:26
No it's a @Component
I do see the log entries being hit
2019-02-07 17:14:42.789 INFO 29928 --- [ctor-http-nio-6] c.devhaus.ms.gateway.RequestIDPreFilter : headers=[Host:"localhost:8081", User-Agent:"curl/7.55.1", Accept:"/", X-Request-ID:"Ugqy9AwT"]
Archimedes Trajano
@trajano
Feb 07 22:32
    @Override
    public Mono<Void> filter(final ServerWebExchange exchange, GatewayFilterChain chain) {
        final String requestID = generateToken(ThreadLocalRandom.current(), 8);
        final String requestURI = exchange.getRequest().getURI().toASCIIString();
        final String method = Objects.requireNonNull(exchange.getRequest().getMethod()).toString();

        MDC.put(MDCKeys.REQUEST_ID, requestID);
        MDC.put(MDCKeys.REQUEST_URI, requestURI);
        MDC.put(MDCKeys.REQUEST_METHOD, method);

        final ServerHttpRequest request = exchange.getRequest().mutate()
            .header(X_REQUEST_ID, requestID)
            .build();

        return chain
            .filter(
                exchange.mutate()
                    .request(request)
                    .build())
            .then(
                Mono.fromRunnable(() -> {
                    log.info("response headers {}", exchange.getResponse().getHeaders());
                    exchange.getResponse().getHeaders().add(X_REQUEST_ID, requestID);
                })
            );
    }