我正在使用Java Couchbase客户端版本1.4.6
我们有几个HA节点。
问题是,如果一个节点发生故障,客户端不会尝试下一个节点,只是继续尝试连接的第一个节点(在它关闭之前)
知道如何设置客户端跳转到群集中的下一个couchbase节点吗?
这是我配置它的方式:
private CouchbaseClient client;
private ArrayList<URI> nodes = new ArrayList<>();
private String uri;
private String bucket;
private String password;
@Override
public void init() {
uri = "host.1,host.2,host.3"
bucket = "default"
password = "password"
try {
addUrlList();
client = new CouchbaseClient(nodes, bucket, password);
} catch (Exception e) {
logger.error("Error connecting to Couchbase: " + e.getMessage(), e);
}
}
private void addUrlList() {
List<String> urlList= Arrays.asList(uri.split(","));
for(String url:urlList)
{
uri = "http://" + url + ":8091/pools";
nodes.add(URI.create(uri));
}
}
那就是例外:
2015-03-12T09:27:54.200+0000 STDIO [ERROR] INFO
2015-03-12T09:27:54.200+0000 STDIO [ERROR] com.couchbase.client.CouchbaseConnection
2015-03-12T09:27:54.200+0000 STDIO [ERROR] :
2015-03-12T09:27:54.200+0000 STDIO [ERROR] Reconnecting {QA sa=host.1/ip.address:11210, #Rops=0, #Wops=0, #iq=0, topRop=null, topWop=null, toWrite=0, interested=0}
2015-03-12T09:27:57.198+0000 STDIO [ERROR] 2015-03-12 09:27:57.198
2015-03-12T09:27:57.199+0000 STDIO [ERROR] INFO
2015-03-12T09:27:57.199+0000 STDIO [ERROR] com.couchbase.client.CouchbaseConnection
2015-03-12T09:27:57.199+0000 STDIO [ERROR] :
2015-03-12T09:27:57.199+0000 STDIO [ERROR] Reconnecting due to exception on {QA sa=host.1/ip.address:11210:11210, #Rops=0, #Wops=0, #iq=0, topRop=null, topWop=null, toWrite=0, interested=0}
2015-03-12T09:27:57.199+0000 STDIO [ERROR] java.net.NoRouteToHostException: No route to host
2015-03-12T09:27:57.200+0000 STDIO [ERROR] at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
2015-03-12T09:27:57.200+0000 STDIO [ERROR] at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:739)
2015-03-12T09:27:57.200+0000 STDIO [ERROR] at net.spy.memcached.MemcachedConnection.handleIO(MemcachedConnection.java:677)
2015-03-12T09:27:57.200+0000 STDIO [ERROR] at net.spy.memcached.MemcachedConnection.handleIO(MemcachedConnection.java:436)
2015-03-12T09:27:57.200+0000 STDIO [ERROR] at com.couchbase.client.CouchbaseConnection.run(CouchbaseConnection.java:325)
2015-03-12T09:27:57.201+0000 STDIO [ERROR] 2015-03-12 09:27:57.201
2015-03-12T09:27:57.201+0000 STDIO [ERROR] WARN
2015-03-12T09:27:57.201+0000 STDIO [ERROR] com.couchbase.client.CouchbaseConnection
2015-03-12T09:27:57.201+0000 STDIO [ERROR] :
2015-03-12T09:27:57.201+0000 STDIO [ERROR] Closing, and reopening {QA sa=host.1/ip.address:11210:11210, #Rops=0, #Wops=0, #iq=0, topRop=null, topWop=null, toWrite=0, interested=0}, attempt 1380.