com.mongodb.MongoTimeoutException
连接到副本集时,我在 AWS 上偶尔遇到错误。rs.status()
例如,我正在使用从 输出的域名进行连接mongo1.production
,mongo2.production
但我仍然遇到超时。
我的代码如下所示:
MongoClientOptions options = new MongoClientOptions.Builder()
.writeConcern(WriteConcern.ACKNOWLEDGED)
.readPreference(ReadPreference.primaryPreferred())
.connectTimeout(30000)
.socketTimeout(60000)
.connectionsPerHost(50)
.threadsAllowedToBlockForConnectionMultiplier(10)
.build();
List<ServerAddress> seeds = new ArrayList<ServerAddress>();
seeds.add(new ServerAddress("mongo1.production:27017"));
seeds.add(new ServerAddress("mongo2.production:27017"));
MongoClient client = new MongoClient(seeds, null, options);