使用Java SDK进行Couchbase连接超时

时间:2015-07-24 08:03:54

标签: java couchbase nosql

我按照couchbase教程连接到远程couchbase服务器,但在我尝试打开默认存储桶后连接超时失败。

我已经检查过我可以在我的电脑上打开couchbase服务器页面(192.xx.xx.xx:8091)

这是我的Java代码

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();

和控制台

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

使用couchbase服务器4

任何帮助将不胜感激。

2 个答案:

答案 0 :(得分:8)

感谢文章https://forums.couchbase.com/t/unable-to-connect-to-db-java-util-concurrent-timeoutexception/4471/3

问题解决了。

需要添加更长的connectTimeout,如下所示

CouchbaseEnvironment env = DefaultCouchbaseEnvironment.builder()
                    .connectTimeout(10000) // 10000ms = 10s, default is 5s
                    .queryEnabled(true).build();

答案 1 :(得分:1)

如果您像我一样在某些情况下喜欢jvm开关, 您可以执行以下操作。

pip install distutils

https://docs.couchbase.com/java-sdk/2.7/client-settings.html

所有客户端设置都可以使用前缀“ com.couchbase”指定