Couchbase connection time out with java sdk

I followed the couchbase tutorial to connect to remote couchbase server, but it failed on connection time out after I try to open default bucket.

I have checked that I can open couchbase server page on my computer(192.xx.xx.xx:8091)

Here is my Java code

CouchbaseEnvironment env = DefaultCouchbaseEnvironment.builder()
.queryEnabled(true)
.build();
Cluster cluster = CouchbaseCluster.create(env,“192.xx.xx.xx:8091”);

Bucket bucket = cluster.openBucket(“default”,“”);
JsonObject user = JsonObject.empty()
.put(“firstname”, “Walter”)
.put(“lastname”, “White”)
.put(“job”, “chemistry teacher”)
.put(“age”, 50);

JsonDocument doc = JsonDocument.create(“walter”, user);
JsonDocument response = bucket.upsert(doc);

JsonDocument walter = bucket.get(“walter”);
System.out.println("Found: " + walter);

cluster.disconnect();

And the console

com.couchbase.client.core.CouchbaseCore
CouchbaseEnvironment: {sslEnabled=false, sslKeystoreFile=‘null’, sslKeystorePassword=‘null’, queryEnabled=true, queryPort=8093, bootstrapHttpEnabled=true, bootstrapCarrierEnabled=true, bootstrapHttpDirectPort=8091, bootstrapHttpSslPort=18091, bootstrapCarrierDirectPort=11210, bootstrapCarrierSslPort=11207, ioPoolSize=4, computationPoolSize=4, responseBufferSize=16384, requestBufferSize=16384, kvServiceEndpoints=1, viewServiceEndpoints=1, queryServiceEndpoints=1, ioPool=NioEventLoopGroup, coreScheduler=CoreScheduler, eventBus=DefaultEventBus, packageNameAndVersion=couchbase-java-client/2.1.4 (git: 2.1.4), dcpEnabled=false, retryStrategy=BestEffort, maxRequestLifetime=75000, retryDelay=ExponentialDelay{growBy 1.0 MICROSECONDS; lower=100, upper=100000}, reconnectDelay=ExponentialDelay{growBy 1.0 MILLISECONDS; lower=32, upper=4096}, observeIntervalDelay=ExponentialDelay{growBy 1.0 MICROSECONDS; lower=10, upper=100000}, keepAliveInterval=30000, autoreleaseAfter=2000, bufferPoolingEnabled=true, queryTimeout=75000, viewTimeout=75000, kvTimeout=2500, connectTimeout=5000, disconnectTimeout=25000, dnsSrvEnabled=false}

com.couchbase.client.core.node.CouchbaseNode$1 call
Connected to Node 192.xx.xx.xx
Exception in thread “main” java.lang.RuntimeException: java.util.concurrent.TimeoutException
at com.couchbase.client.java.util.Blocking.blockForSingle(Blocking.java:93)
at com.couchbase.client.java.CouchbaseCluster.openBucket(CouchbaseCluster.java:108)
at com.couchbase.client.java.CouchbaseCluster.openBucket(CouchbaseCluster.java:99)
at com.couchbase.client.java.CouchbaseCluster.openBucket(CouchbaseCluster.java:89)
at HelloCouchbase.main(HelloCouchbase.java:19)
Caused by: java.util.concurrent.TimeoutException
… 5 more
Using couchbase server 4

Any help will be appreciated.

Thanks to the article Unable to connect to DB - java.util.concurrent.TimeoutException

The problem is solved.

2 Likes