Search in sources :

Example 1 with MongoClientConfig

use of io.quarkus.mongodb.runtime.MongoClientConfig 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));
            }
        }
    });
}
Also used : MongoClient(com.mongodb.client.MongoClient) ReactiveMongoClient(io.quarkus.mongodb.reactive.ReactiveMongoClient) ReactiveMongoClient(io.quarkus.mongodb.reactive.ReactiveMongoClient) InstanceHandle(io.quarkus.arc.InstanceHandle) MongoClientConfig(io.quarkus.mongodb.runtime.MongoClientConfig)

Example 2 with MongoClientConfig

use of io.quarkus.mongodb.runtime.MongoClientConfig in project quarkus by quarkusio.

the class BeanUtils method getDatabaseName.

public static String getDatabaseName(MongoEntity mongoEntity, String clientBeanName) {
    MongoClients mongoClients = Arc.container().instance(MongoClients.class).get();
    MongoClientConfig matchingMongoClientConfig = mongoClients.getMatchingMongoClientConfig(clientBeanName);
    if (matchingMongoClientConfig.database.isPresent()) {
        return matchingMongoClientConfig.database.get();
    }
    if (!clientBeanName.equals(MongoClientBeanUtil.DEFAULT_MONGOCLIENT_NAME)) {
        MongoClientConfig defaultMongoClientConfig = mongoClients.getMatchingMongoClientConfig(MongoClientBeanUtil.DEFAULT_MONGOCLIENT_NAME);
        if (defaultMongoClientConfig.database.isPresent()) {
            return defaultMongoClientConfig.database.get();
        }
    }
    if (mongoEntity == null) {
        throw new IllegalArgumentException("The database property was not configured for the default Mongo Client (via 'quarkus.mongodb.database'");
    }
    if (mongoEntity.clientName().isEmpty()) {
        throw new IllegalArgumentException("The database attribute was not set for the @MongoEntity annotation " + "and neither was the database property configured for the default Mongo Client (via 'quarkus.mongodb.database')");
    }
    throw new IllegalArgumentException(String.format("The database attribute was not set for the @MongoEntity annotation neither was the database property configured for the named Mongo Client (via 'quarkus.mongodb.%s.database')", mongoEntity.clientName()));
}
Also used : MongoClients(io.quarkus.mongodb.runtime.MongoClients) MongoClientConfig(io.quarkus.mongodb.runtime.MongoClientConfig)

Aggregations

MongoClientConfig (io.quarkus.mongodb.runtime.MongoClientConfig)2 MongoClient (com.mongodb.client.MongoClient)1 InstanceHandle (io.quarkus.arc.InstanceHandle)1 ReactiveMongoClient (io.quarkus.mongodb.reactive.ReactiveMongoClient)1 MongoClients (io.quarkus.mongodb.runtime.MongoClients)1