use of io.quarkus.mongodb.reactive.ReactiveMongoClient in project quarkus by quarkusio.
the class NamedReactiveMongoClientConfigTest method assertProperConnection.
private void assertProperConnection(ReactiveMongoClient client, int expectedPort) {
assertThat(unwrapper.apply(client)).isInstanceOfSatisfying(ReactiveMongoClientImpl.class, rc -> {
Field mongoClientField;
try {
mongoClientField = ReactiveMongoClientImpl.class.getDeclaredField("client");
} catch (NoSuchFieldException e) {
throw new RuntimeException(e);
}
mongoClientField.setAccessible(true);
MongoClient c;
try {
c = (MongoClientImpl) mongoClientField.get(rc);
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
}
assertThat(c.getClusterDescription().getClusterSettings().getHosts()).singleElement().satisfies(sa -> {
assertThat(sa.getPort()).isEqualTo(expectedPort);
});
});
}
use of io.quarkus.mongodb.reactive.ReactiveMongoClient in project quarkus by quarkusio.
the class MongoHealthCheck method configure.
public void configure(MongodbConfig config) {
Iterable<InstanceHandle<MongoClient>> handle = Arc.container().select(MongoClient.class, Any.Literal.INSTANCE).handles();
Iterable<InstanceHandle<ReactiveMongoClient>> reactiveHandlers = Arc.container().select(ReactiveMongoClient.class, Any.Literal.INSTANCE).handles();
if (config.defaultMongoClientConfig != null) {
MongoClient client = getClient(handle, null);
ReactiveMongoClient reactiveClient = getReactiveClient(reactiveHandlers, null);
if (client != null) {
checks.add(new MongoClientCheck(CLIENT_DEFAULT, client, config.defaultMongoClientConfig));
}
if (reactiveClient != null) {
checks.add(new ReactiveMongoClientCheck(CLIENT_DEFAULT_REACTIVE, reactiveClient, config.defaultMongoClientConfig));
}
}
config.mongoClientConfigs.forEach(new BiConsumer<String, MongoClientConfig>() {
@Override
public void accept(String name, MongoClientConfig cfg) {
MongoClient client = getClient(handle, name);
ReactiveMongoClient reactiveClient = getReactiveClient(reactiveHandlers, name);
if (client != null) {
checks.add(new MongoClientCheck(name, client, config.defaultMongoClientConfig));
}
if (reactiveClient != null) {
checks.add(new ReactiveMongoClientCheck(name, reactiveClient, config.defaultMongoClientConfig));
}
}
});
}
use of io.quarkus.mongodb.reactive.ReactiveMongoClient in project quarkus by quarkusio.
the class ReactiveMongoOperations method mongoDatabase.
private ReactiveMongoDatabase mongoDatabase(MongoEntity mongoEntity) {
ReactiveMongoClient mongoClient = clientFromArc(mongoEntity, ReactiveMongoClient.class, true);
if (mongoEntity != null && !mongoEntity.database().isEmpty()) {
return mongoClient.getDatabase(mongoEntity.database());
}
String databaseName = getDefaultDatabaseName(mongoEntity);
return mongoClient.getDatabase(databaseName);
}
use of io.quarkus.mongodb.reactive.ReactiveMongoClient in project EDDI by labsai.
the class PersistenceModule method provideMongoDB.
@Produces
@ApplicationScoped
public MongoDatabase provideMongoDB(@ConfigProperty(name = "mongodb.connectionString") String connectionString, @ConfigProperty(name = "mongodb.database") String database) {
BsonFactory bsonFactory = new BsonFactory();
bsonFactory.enable(BsonParser.Feature.HONOR_DOCUMENT_LENGTH);
ReactiveMongoClient client = new ReactiveMongoClientImpl(MongoClients.create(buildMongoClientOptions(ReadPreference.nearest(), connectionString, bsonFactory)));
registerMongoClientShutdownHook(client);
return client.getDatabase(database).unwrap();
}
use of io.quarkus.mongodb.reactive.ReactiveMongoClient in project quarkus by quarkusio.
the class NamedReactiveMongoClientConfigTest method assertNoDefaultClient.
private void assertNoDefaultClient() {
boolean hasDefault = false;
for (InstanceHandle<ReactiveMongoClient> handle : Arc.container().select(ReactiveMongoClient.class).handles()) {
InjectableBean<ReactiveMongoClient> bean = handle.getBean();
for (Annotation qualifier : bean.getQualifiers()) {
if (qualifier.annotationType().equals(Default.class)) {
hasDefault = true;
}
}
}
Assertions.assertFalse(hasDefault, "The default reactive mongo client should not have been present as it is not used in any injection point");
}
Aggregations