use of com.mongodb.reactivestreams.client.MongoClient in project micronaut-mongodb by micronaut-projects.
the class MongoHealthIndicator method checkRegisteredMongoClient.
private Publisher<HealthResult> checkRegisteredMongoClient(BeanRegistration<MongoClient> registration) {
MongoClient mongoClient = registration.getBean();
String databaseName = "mongodb (" + registration.getIdentifier().getName() + ")";
Flux<Map<String, String>> databasePings = Flux.from(pingMongo(mongoClient)).map(this::getVersionDetails).timeout(Duration.of(10, ChronoUnit.SECONDS)).retry(3);
return databasePings.map(detail -> buildStatusUp(databaseName, detail)).onErrorResume(throwable -> Flux.just(buildStatusDown(throwable, databaseName)));
}
use of com.mongodb.reactivestreams.client.MongoClient in project gravitee-access-management by gravitee-io.
the class MongoAuthenticationProviderConfiguration method mongoClient.
@Bean
public MongoClient mongoClient() {
MongoClient mongoClient;
if ((this.configuration.getUri() != null) && (!this.configuration.getUri().isEmpty())) {
mongoClient = MongoClients.create(this.configuration.getUri());
} else {
ServerAddress serverAddress = new ServerAddress(this.configuration.getHost(), this.configuration.getPort());
ClusterSettings clusterSettings = ClusterSettings.builder().hosts(asList(serverAddress)).build();
MongoClientSettings.Builder settings = MongoClientSettings.builder().applyToClusterSettings(clusterBuilder -> clusterBuilder.applySettings(clusterSettings));
if (this.configuration.isEnableCredentials()) {
MongoCredential credential = MongoCredential.createCredential(this.configuration.getUsernameCredentials(), this.configuration.getDatabaseCredentials(), this.configuration.getPasswordCredentials().toCharArray());
settings.credential(credential);
}
mongoClient = MongoClients.create(settings.build());
}
return mongoClient;
}
use of com.mongodb.reactivestreams.client.MongoClient in project gravitee-access-management by gravitee-io.
the class EmbeddedClient method afterPropertiesSet.
@Override
public void afterPropertiesSet() throws Exception {
final IMongodConfig mongodConfig = new MongodConfigBuilder().version(Version.Main.PRODUCTION).build();
IRuntimeConfig runtimeConfig = new RuntimeConfigBuilder().defaultsWithLogger(Command.MongoD, logger).processOutput(ProcessOutput.getDefaultInstanceSilent()).build();
MongodStarter runtime = MongodStarter.getInstance(runtimeConfig);
MongodExecutable mongodExecutable = runtime.prepare(mongodConfig);
mongod = mongodExecutable.start();
// cluster configuration
ClusterSettings clusterSettings = ClusterSettings.builder().hosts(Collections.singletonList(new ServerAddress(mongodConfig.net().getServerAddress().getHostName(), mongodConfig.net().getPort()))).build();
// codec configuration
CodecRegistry pojoCodecRegistry = fromRegistries(MongoClients.getDefaultCodecRegistry(), fromProviders(PojoCodecProvider.builder().automatic(true).build()));
MongoClientSettings settings = MongoClientSettings.builder().applyToClusterSettings(clusterBuilder -> clusterBuilder.applySettings(clusterSettings)).codecRegistry(pojoCodecRegistry).writeConcern(WriteConcern.ACKNOWLEDGED).build();
mongoClient = MongoClients.create(settings);
mongoDatabase = mongoClient.getDatabase(databaseName);
}
use of com.mongodb.reactivestreams.client.MongoClient in project gravitee-access-management by gravitee-io.
the class MongoReporterConfiguration method mongoClient.
@Bean
public MongoClient mongoClient() {
// Client settings
com.mongodb.MongoClientSettings.Builder builder = com.mongodb.MongoClientSettings.builder();
builder.writeConcern(WriteConcern.ACKNOWLEDGED);
// codec configuration for pojo mapping
CodecRegistry pojoCodecRegistry = fromRegistries(MongoClients.getDefaultCodecRegistry(), fromProviders(PojoCodecProvider.builder().automatic(true).build()));
builder.codecRegistry(pojoCodecRegistry);
if ((this.configuration.getUri() != null) && (!this.configuration.getUri().isEmpty())) {
// The builder can be configured with default options, which may be overridden by options specified in
// the URI string.
com.mongodb.MongoClientSettings settings = builder.codecRegistry(pojoCodecRegistry).applyConnectionString(new ConnectionString(this.configuration.getUri())).build();
return MongoClients.create(settings);
} else {
// Manual configuration
// Servers host
ServerAddress serverAddress = new ServerAddress(this.configuration.getHost(), this.configuration.getPort());
ClusterSettings clusterSettings = ClusterSettings.builder().hosts(asList(serverAddress)).build();
// Mongo credentials
if (this.configuration.isEnableCredentials()) {
MongoCredential credential = MongoCredential.createCredential(this.configuration.getUsernameCredentials(), this.configuration.getDatabaseCredentials(), this.configuration.getPasswordCredentials().toCharArray());
builder.credential(credential);
}
com.mongodb.MongoClientSettings settings = builder.applyToClusterSettings(builder1 -> builder1.applySettings(clusterSettings)).build();
return MongoClients.create(settings);
}
}
Aggregations