As per documentation, there is possible to use multiple mongodb clients quarkus.mongodb.[optional name.][mongo connection property] ex.:
quarkus.mongodb.users.connection-string = mongodb://mongo2:27017/userdb
Then to inject the named client such as:
@Inject
@MongoClientName("users")
MongoClient mongoClient1;
I try to use the @MongoEntity with multiple connection, as I see it has a field clientName.
but when I try to run, it throws an exception.
Expected behavior
Possibility to use multiple MongoDB connections (clients).
Actual behavior
using multiple mongodb connection is not working, only default (single) one.
How to Reproduce?
BacklogEntity class
@MongoEntity(clientName = "inventory", collection = "backlog")
@EqualsAndHashCode(callSuper = false)
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class BacklogEntity extends PanacheMongoEntityBase {
@BsonId
String id;
public static PanacheQuery<BacklogEntity> findByIds(final List<String> list) {
return find("_id in ?1", list);
}
}
When I run I get:
java.lang.IllegalStateException: Unable to find MongoClient bean for entity @io.quarkus.mongodb.panache.common.MongoEntity(readPreference="", database="inventory", collection="backlog", clientName="inventory")
at io.quarkus.mongodb.panache.common.runtime.BeanUtils.clientFromArc(BeanUtils.java:58)
at io.quarkus.mongodb.panache.common.runtime.MongoOperations.mongoDatabase(MongoOperations.java:399)
at io.quarkus.mongodb.panache.common.runtime.MongoOperations.mongoCollection(MongoOperations.java:193)
at io.quarkus.mongodb.panache.common.runtime.MongoOperations.mongoCollection(MongoOperations.java:395)
at io.quarkus.mongodb.panache.common.runtime.MongoOperations.persist(MongoOperations.java:73)
at io.quarkus.mongodb.panache.PanacheMongoEntityBase.persist(PanacheMongoEntityBase.java:36)
at com.asml.asml.vcp.datacontinuity.export.BacklogEntityTest.testPersist(BacklogEntityTest.java:40)
at java.base/java.lang.reflect.Method.invoke(Method.java:580)
at io.quarkus.test.junit.QuarkusTestExtension.runExtensionMethod(QuarkusTestExtension.java:1017)
at io.quarkus.test.junit.QuarkusTestExtension.interceptTestMethod(QuarkusTestExtension.java:831)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
And in the logs I get both
Creating container for image: docker.io/mongo:4.4
Creating container for image: mongo:7
Where did the "docker.io/mongo:4.4" come from ? In my MongoDBLifecycleManager I only specify the mongo:7 image to be used. I understand this is some default, but I am not interested in using this, that's why I specify a different version. This is also a bug !
If I try to use BacklogEntity defined with only @MongoEntity(database = "inventory", collection = "backlog"), of course it uses the default connection (no name) and therefore is decoupled from the named connection (inventory), and fails next test.
There is the need to run with named connection, as this is only one connection test, but I want to run with multiple ones, so just bypassing and use the default, no name connection is not an option.
From @interface MongoEntity I see
/**
The name of the MongoDB client (if not set the default client will be used).
*/
String clientName() default "";
So it should work when setting the client name... therefore is a bug.
Output of uname -a or ver
windows
Output of java -version
21
Quarkus version or git rev
3.11.3, 3.12
Build tool (ie. output of mvnw --version or gradlew --version)
Describe the bug
As per documentation, there is possible to use multiple mongodb clients quarkus.mongodb.[optional name.][mongo connection property] ex.: quarkus.mongodb.users.connection-string = mongodb://mongo2:27017/userdb
Then to inject the named client such as: @Inject @MongoClientName("users") MongoClient mongoClient1;
I try to use the @MongoEntity with multiple connection, as I see it has a field clientName. but when I try to run, it throws an exception.
Expected behavior
Possibility to use multiple MongoDB connections (clients).
Actual behavior
using multiple mongodb connection is not working, only default (single) one.
How to Reproduce?
BacklogEntity class
application.properties quarkus.mongodb.inventory.connection-string = mongodb://localhost:27017 quarkus.mongodb.inventory.database = inventory
MongoDBLifecycleManager class
BacklogEntityTest test class
When I run I get: java.lang.IllegalStateException: Unable to find MongoClient bean for entity @io.quarkus.mongodb.panache.common.MongoEntity(readPreference="", database="inventory", collection="backlog", clientName="inventory") at io.quarkus.mongodb.panache.common.runtime.BeanUtils.clientFromArc(BeanUtils.java:58) at io.quarkus.mongodb.panache.common.runtime.MongoOperations.mongoDatabase(MongoOperations.java:399) at io.quarkus.mongodb.panache.common.runtime.MongoOperations.mongoCollection(MongoOperations.java:193) at io.quarkus.mongodb.panache.common.runtime.MongoOperations.mongoCollection(MongoOperations.java:395) at io.quarkus.mongodb.panache.common.runtime.MongoOperations.persist(MongoOperations.java:73) at io.quarkus.mongodb.panache.PanacheMongoEntityBase.persist(PanacheMongoEntityBase.java:36) at com.asml.asml.vcp.datacontinuity.export.BacklogEntityTest.testPersist(BacklogEntityTest.java:40) at java.base/java.lang.reflect.Method.invoke(Method.java:580) at io.quarkus.test.junit.QuarkusTestExtension.runExtensionMethod(QuarkusTestExtension.java:1017) at io.quarkus.test.junit.QuarkusTestExtension.interceptTestMethod(QuarkusTestExtension.java:831) at java.base/java.util.ArrayList.forEach(ArrayList.java:1596) at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
And in the logs I get both Creating container for image: docker.io/mongo:4.4 Creating container for image: mongo:7
Where did the "docker.io/mongo:4.4" come from ? In my MongoDBLifecycleManager I only specify the mongo:7 image to be used. I understand this is some default, but I am not interested in using this, that's why I specify a different version. This is also a bug !
If I try to use BacklogEntity defined with only @MongoEntity(database = "inventory", collection = "backlog"), of course it uses the default connection (no name) and therefore is decoupled from the named connection (inventory), and fails next test.
There is the need to run with named connection, as this is only one connection test, but I want to run with multiple ones, so just bypassing and use the default, no name connection is not an option.
From @interface MongoEntity I see /**
So it should work when setting the client name... therefore is a bug.
Output of
uname -a
orver
windows
Output of
java -version
21
Quarkus version or git rev
3.11.3, 3.12
Build tool (ie. output of
mvnw --version
orgradlew --version
)mvn 3.9.7
Additional information
Please don't be ignorant with these bugs.