use of com.mongodb.async.client.MongoClientSettings.Builder in project spring-boot by spring-projects.
the class ReactiveMongoClientFactory method createNetworkMongoClient.
private MongoClient createNetworkMongoClient(MongoClientSettings settings) {
if (hasCustomAddress() || hasCustomCredentials()) {
if (this.properties.getUri() != null) {
throw new IllegalStateException("Invalid mongo configuration, " + "either uri or host/port/credentials must be specified");
}
Builder builder = builder(settings);
if (hasCustomCredentials()) {
List<MongoCredential> credentials = new ArrayList<>();
String database = this.properties.getAuthenticationDatabase() == null ? this.properties.getMongoClientDatabase() : this.properties.getAuthenticationDatabase();
credentials.add(MongoCredential.createCredential(this.properties.getUsername(), database, this.properties.getPassword()));
builder.credentialList(credentials);
}
String host = this.properties.getHost() == null ? "localhost" : this.properties.getHost();
int port = this.properties.getPort() != null ? this.properties.getPort() : MongoProperties.DEFAULT_PORT;
ClusterSettings clusterSettings = ClusterSettings.builder().hosts(Collections.singletonList(new ServerAddress(host, port))).build();
builder.clusterSettings(clusterSettings);
return MongoClients.create(builder.build());
}
ConnectionString connectionString = new ConnectionString(this.properties.determineUri());
return MongoClients.create(createBuilder(settings, connectionString).build());
}
use of com.mongodb.async.client.MongoClientSettings.Builder in project spring-boot by spring-projects.
the class ReactiveMongoClientFactory method createEmbeddedMongoClient.
private MongoClient createEmbeddedMongoClient(MongoClientSettings settings, int port) {
Builder builder = builder(settings);
String host = this.properties.getHost() == null ? "localhost" : this.properties.getHost();
ClusterSettings clusterSettings = ClusterSettings.builder().hosts(Collections.singletonList(new ServerAddress(host, port))).build();
builder.clusterSettings(clusterSettings);
return MongoClients.create(builder.build());
}
Aggregations