Carlos Alberto
Carlos Alberto

Reputation: 8605

Spring Cloud Hystrix fails at first command call

I noticed the first Hystrix command always calls my fallback, and after that the following calls works fine in Spring Cloud Netflix.

Is there any setting should I set to avoid it? Why does it happen?

Upvotes: 6

Views: 3294

Answers (2)

lubumbax
lubumbax

Reputation: 265

I addressed that by sending the failed request again from the fallback method, this time finding the IP of one of the remote pods with DicoveryClient:

private String getNameFallback(int delay) {
    RestTemplate rt = new RestTemplate();
    return rt.getForObject(getUrl(delay), String.class);
}

private String getUrl(int delay) {
    String url = String.format("http://%s/name?delay=%d", SERVICE_ID, delay);
    if (discoveryClient != null) {
        Optional<ServiceInstance> svc = discoveryClient.getInstances(SERVICE_ID).stream().findFirst();
        if (svc.isPresent()) {
            String host = svc.get().getHost();
            int port = svc.get().getPort();
            url = "http://" + host + ":" + port + "?delay=" + delay;
        }
    }
    return url;
}

You can find more details here

Upvotes: 0

ivanenok
ivanenok

Reputation: 624

looks like a side effect of an infrastructure initialization and as timeout on it https://groups.google.com/d/msg/hystrixoss/_jnxAyS20lA/fWo0ZAHoxt8J

Upvotes: 9

Related Questions