2019-07-01 上海
对于 v3.0.x,多节点连接如下所示:
remote:{ip_1},{ip_2},{ip_3}/{database_name}
OrientDB JavaApi 演示:
String url = "remote:{ip_1},{ip_2},{ip_3}/{database_name}";
String username = "username";
String password = "password";
// FIXME: I'm not sure the pool configuration is suit for you, may be you can use the default config.
OrientDBConfigBuilder poolCfg = OrientDBConfig.builder();
poolCfg.addConfig(OGlobalConfiguration.DB_POOL_MIN, 1);
poolCfg.addConfig(OGlobalConfiguration.DB_POOL_MAX, 100);
poolCfg.addConfig(OGlobalConfiguration.CLIENT_CONNECTION_STRATEGY, OStorageRemote.CONNECTION_STRATEGY.ROUND_ROBIN_CONNECT);
ODatabasePool pool = new ODatabasePool(url, userName, password, poolCfg.build());
ODatabaseSession session = pool.acquire();
session.begin();
....
OrientDB 源代码
public OrientDB(String url, String serverUser, String serverPassword, OrientDBConfig configuration) {
int pos;
String what;
if ((pos = url.indexOf(':')) > 0) {
what = url.substring(0, pos);
} else {
what = url;
}
if ("embedded".equals(what) || "memory".equals(what) || "plocal".equals(what))
internal = OrientDBInternal.embedded(url.substring(url.indexOf(':') + 1), configuration);
=========================== HERE =========================
else if ("remote".equals(what))
internal = OrientDBInternal.remote(url.substring(url.indexOf(':') + 1).split(","), configuration);
=========================== HERE =========================
else
throw new IllegalArgumentException("Wrong url:`" + url + "`");
this.serverUser = serverUser;
this.serverPassword = serverPassword;
}