I am using a newer Couchbase server hosted on cloud server. I can connect to a cluster and bucket but every time I try to do upsert into the bucket, I get a timeout error. I have tried to use timeoutConfig to timeout for around 60 seconds, which leads it to keep trying but fails and gives the timeout error. Is there a suggestion to try something else or debug further?
Here is my code:
package com;
import com.couchbase.client.java.env.ClusterEnvironment;
import com.couchbase.client.core.env.*;
import com.couchbase.client.java.*;
import com.couchbase.client.java.kv.*;
import com.couchbase.client.java.json.*;
import com.couchbase.client.java.query.*;
import java.time.Duration;
public class HelloCouchbaseJava {
public static void main(String[] args) {
String bucketName = "test";
String username = "test ";
String password = "test";
String connectionString = "couchbase://11.22.5.211";
ClusterEnvironment env = ClusterEnvironment.builder()
.timeoutConfig(TimeoutConfig
.kvTimeout(Duration.ofSeconds(60))
.queryTimeout(Duration.ofSeconds(10)))
.build();
ClusterOptions clusterOptions = ClusterOptions.clusterOptions(username, password);
clusterOptions.environment(env);
Cluster cluster = Cluster.connect(connectionString, clusterOptions);
Bucket bucket = cluster.bucket(bucketName);
bucket.waitUntilReady(Duration.ofSeconds(60));
//UPSERT
Collection collection = bucket.defaultCollection();
MutationResult upsertResult = collection.upsert(
"my-document",
JsonObject.create().put("name", "mike")
);
//GET
GetResult getResult = collection.get("my-document");
String name = getResult.contentAsObject().getString("name");
System.out.println(name); // name == "mike"
QueryResult result = cluster.query("select \"Hello World\" as greeting");
System.out.println(result.rowsAsObject());
}
}
Error is this:
TimeoutException: Did not observe any item or terminal signal within 10000ms in 'source(MonoDefer)' (and no fallback has been configured)