Search in sources :

Example 1 with ReactiveMongoClient

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);
        });
    });
}
Also used : Field(java.lang.reflect.Field) ReactiveMongoClient(io.quarkus.mongodb.reactive.ReactiveMongoClient) MongoClient(com.mongodb.reactivestreams.client.MongoClient) ReactiveMongoClientImpl(io.quarkus.mongodb.impl.ReactiveMongoClientImpl)

Example 2 with ReactiveMongoClient

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));
            }
        }
    });
}
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 3 with ReactiveMongoClient

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);
}
Also used : ReactiveMongoClient(io.quarkus.mongodb.reactive.ReactiveMongoClient)

Example 4 with ReactiveMongoClient

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();
}
Also used : ReactiveMongoClient(io.quarkus.mongodb.reactive.ReactiveMongoClient) ReactiveMongoClientImpl(io.quarkus.mongodb.impl.ReactiveMongoClientImpl) BsonFactory(de.undercouch.bson4jackson.BsonFactory) Produces(javax.ws.rs.Produces) ApplicationScoped(javax.enterprise.context.ApplicationScoped)

Example 5 with ReactiveMongoClient

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");
}
Also used : ReactiveMongoClient(io.quarkus.mongodb.reactive.ReactiveMongoClient) Annotation(java.lang.annotation.Annotation)

Aggregations

ReactiveMongoClient (io.quarkus.mongodb.reactive.ReactiveMongoClient)5 ReactiveMongoClientImpl (io.quarkus.mongodb.impl.ReactiveMongoClientImpl)2 MongoClient (com.mongodb.client.MongoClient)1 MongoClient (com.mongodb.reactivestreams.client.MongoClient)1 BsonFactory (de.undercouch.bson4jackson.BsonFactory)1 InstanceHandle (io.quarkus.arc.InstanceHandle)1 MongoClientConfig (io.quarkus.mongodb.runtime.MongoClientConfig)1 Annotation (java.lang.annotation.Annotation)1 Field (java.lang.reflect.Field)1 ApplicationScoped (javax.enterprise.context.ApplicationScoped)1 Produces (javax.ws.rs.Produces)1