Skip to content
This repository has been archived by the owner on Jul 27, 2023. It is now read-only.

Consul Cache #81

Closed
amitgilad3 opened this issue Nov 15, 2015 · 3 comments
Closed

Consul Cache #81

amitgilad3 opened this issue Nov 15, 2015 · 3 comments

Comments

@amitgilad3
Copy link

Hi ,
I am trying to use consul cache and i keep getting the following error :
ERROR com.orbitz.consul.cache.ConsulCache - Error getting response from consul. will retry in 10 SECONDS

why do i get this error??

code example:
LOGGER.info("Initializing consul cache!!!!!");
com.orbitz.consul.Consul consul = com.orbitz.consul.Consul.builder().build();
KeyValueClient kvClient = consul.keyValueClient();

    kvCache = KVCache.newCache(
            kvClient, applicationName, watchTimeout
    );
    kvCache.start();

    if (!kvCache.awaitInitialized(10, TimeUnit.SECONDS)) {
        LOGGER.error("Failed to listen to reportservice in consul");
    }
    kvCache.addListener(consulCacheListener);
    LOGGER.info(" consul cache Initialized !!!!!");
@rickfast
Copy link
Owner

The Consul Client throws a TimeoutException when 10 seconds is up and no data is returned and the failure callback is executed. Likely, there's no problem. It's just a misleading log message.

@DimaGolomozy
Copy link

It is a problem. every TimeoutException we have a printing to log, and kvClient.getValues method is executed again. so the watchTimeout(KVCache argument) is useless.

The exception caused from using:
'org.apache.cxf:cxf-rt-rs-client:3.0.3'
'org.apache.cxf:cxf-rt-transports-http-hc:3.0.3'
Using them, creates a Client with ReceiveTimeout=6000 -> 1 min (https://cxf.apache.org/javadoc/latest/org/apache/cxf/transports/http/configuration/HTTPClientPolicy.html)
this why every 1 min (plus the 10 seconds waiting for the executorService.schedule) you get the TimeoutException.
If you configure the watchTimeout to be less than a minute, the exception won't appear (but you lose the timeout "logic")

solve this with configure the Client with another timeout value, and build Consul using .withClientBuilder() constructor.
or like I solved it by switching to:
'org.glassfish.jersey.core:jersey-client:2.22.1'
'javax.ws.rs:javax.ws.rs-api:2.0.1'

BUT! when initializing KVCache, the watchTimeout is limited up to 10m.
https://www.consul.io/docs/agent/http.html (Blocking Queries)

Enjoy :)

@xiaogaozi
Copy link

The latest consul-client has use OkHttp now, so if you encounter this situation, you could make read timeout longer use Consul.Builder.withReadTimeoutMillis(). If you don't, OkHttp default set read timeout to 10 seconds.

Consul consul = Consul.builder()
        .withReadTimeoutMillis(60 * 1000)  // 60 seconds
        .build();

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants