我在couchbases的网站上使用了你的示例代码,我使用的是java,jdk版本是1.6。通过键设置和获取值是好的,但是在查询视图时,总是出现错误。
这是我的代码:
package src.main.java;
import com.couchbase.client.CouchbaseClient;
import com.couchbase.client.protocol.views.Query;
import com.couchbase.client.protocol.views.View;
import com.couchbase.client.protocol.views.ViewResponse;
import com.couchbase.client.protocol.views.ViewRow;
import java.net.URI;
import java.util.Arrays;
import java.util.List;
public class HelloWorld {
public static void main(String[] args) throws Exception {
// (Subset) of nodes in the cluster to establish a connection
List<URI> hosts = Arrays.asList(
new URI("http://192.168.174.128:8091/pools")
);
// Name of the Bucket to connect to
String bucket = "default";
// Password of the bucket (empty) string if none
String password = "";
// Connect to the Cluster
CouchbaseClient client = new CouchbaseClient(hosts, bucket, password);
// 1: Load the View infos
String designDoc = "users";
String viewName = "by_firstname";
View view = client.getView(designDoc, viewName);
// 2: Create a Query object to customize the Query
Query query = new Query();
query.setIncludeDocs(true); // Include the full document body
// 3: Actually Query the View and return the results
ViewResponse response = client.query(view, query);
// 4: Iterate over the Data and print out the full document
for (ViewRow row : response) {
System.out.println(row.getDocument());
}
// Shutting down properly
client.shutdown();
}
}
这是错误日志
2013-08-03 11:17:21.779 ERROR com.couchbase.client.ViewNode$EventLogger: Connection timed out: [192.168.174.128/192.168.174.128:8092]
Exception in thread "main" java.lang.RuntimeException: Timed out waiting for operation
at com.couchbase.client.internal.HttpFuture.get(HttpFuture.java:67)
at com.couchbase.client.CouchbaseClient.getView(CouchbaseClient.java:483)
at src.main.java.HelloWorld.main(HelloWorld.java:75)
Caused by: java.util.concurrent.TimeoutException: Timed out waiting for operation
at com.couchbase.client.internal.HttpFuture.waitForAndCheckOperation(HttpFuture.java:85)
at com.couchbase.client.internal.HttpFuture.get(HttpFuture.java:74)
at com.couchbase.client.internal.HttpFuture.get(HttpFuture.java:64)
... 2 more
从 Web 管理控制台我可以看到我已经发布了视图。在那个控制台中也可以使用。防火墙已关闭,我尝试了 couchbase 2.0.0 社区版和 2.1.1 社区版。