I'm experiencing occasional com.mongodb.MongoTimeoutException
errors on AWS when connecting to a replica set. I'm connecting using the domain name that's being outputed from rs.status()
, for example, mongo1.production
and mongo2.production
but I still get the timeouts.
My code looks like:
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);