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 <init>
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.
Due to how Log4J is used by Couchbase we are not aware of any Couchbase products vulnerable to these security issues.
kvTimeout. long kvTimeout() The default timeout for binary (key/value) operations, set to DefaultCouchbaseEnvironment.
Thanks to the article https://forums.couchbase.com/t/unable-to-connect-to-db-java-util-concurrent-timeoutexception/4471/3
The problem is solved.
It need to add longer connectTimeout as below
CouchbaseEnvironment env = DefaultCouchbaseEnvironment.builder()
.connectTimeout(10000) // 10000ms = 10s, default is 5s
.queryEnabled(true).build();
If you are like me who likes jvm switches in certain cases, you can do the following.
java -Xms1g -Xmx4g -Dspring.profiles.active=local -Dcom.couchbase.connectTimeout=60000 <program>
https://docs.couchbase.com/java-sdk/2.7/client-settings.html
all client settings can be specified with prefix "com.couchbase"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With