avidCoder
8 years agoSuper Contributor
Getting java.util.concurrent.timeoutexception intermittently while connecting to couchbase
I am using Ready API 1.9.0 version to fetch the documents from the couchbase. Sometimes it works but sometimes it gives java.util.concurrent.timeoutexception. Below is the code I have written:-
@Grab('com.couchbase.client:java-client:2.5.5')
import com.couchbase.client.java.Bucket;
import com.couchbase.client.java.Cluster;
import com.couchbase.client.java.CouchbaseCluster;
import com.couchbase.client.java.document.json.JsonObject;
import com.couchbase.client.java.query.*;
import com.couchbase.client.java.document.json.JsonArray;
import com.couchbase.client.java.env.DefaultCouchbaseEnvironment;
def env = DefaultCouchbaseEnvironment.builder().connectTimeout(10000).queryTimeout(10000).build()
CouchbaseCluster cluster = CouchbaseCluster.create(env, IP)
Bucket bucket = cluster.openBucket(user, pass)
String doc = "EID_1900"
JsonObject docInv = getInventoryDocument(bucket, doc)
log.info dovInv
def getInventoryDocument(Bucket bucket, String val) {
try {
if (bucket.get(val) != null) {
JsonObject docs= bucket.get(val).content()
return docs;
} else
return null;
} catch (Exception e) {
if (bucket.get(val) != null) {
JsonObject docs= bucket.get(val, 1, TimeUnit.MINUTES).content();
return docs;
} else
return null;
}
}
Could you please help me with this?