使用libbase Mongodb扩展与Quarkus



尝试使用ququbase -mongodb扩展与Quarkus。没有任何成功。有人能给我举个例子吗?

application.yamlcontents:

quarkus:
mongodb:
connection-string: mongodb://localhost:27017
write-concern:
journal: false
database: foo1
liquibase:
migrate-at-start: true
change-log: db/changeLog.yaml

db/changeLog.yamlcontents:

databaseChangeLog:
- include:
file: changesets/foo.json

build.gradle包含:


implementation "io.quarkus:quarkus-liquibase"
implementation "org.liquibase.ext:liquibase-mongodb:${liquibaseVersion}"
implementation "org.mongodb:mongodb-driver-sync:${mongodbVersion}"

输出:

SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.slf4j.impl.Slf4jLoggerFactory]
__  ____  __  _____   ___  __ ____  ______ 
--/ __ / / / / _ | / _ / //_/ / / / __/ 
-/ /_/ / /_/ / __ |/ , _/ ,< / /_/ /    
--________/_/ |_/_/|_/_/|_|____/___/   
2021-03-07 12:26:39,254 WARN  [io.qua.dep.QuarkusAugmentor] (main) Using Java versions older than 11 to build Quarkus applications is deprecated and will be disallowed in a future release!
2021-03-07 12:26:39,573 WARN  [io.qua.agr.dep.AgroalProcessor] (build-24) The Agroal dependency is present but no JDBC datasources have been defined.
2021-03-07 12:26:40,583 INFO  [org.mon.dri.cluster] (Quarkus Main Thread) Cluster created with settings {hosts=[localhost:27017], mode=SINGLE, requiredClusterType=UNKNOWN, serverSelectionTimeout='30000 ms'}
2021-03-07 12:26:40,595 INFO  [org.mon.dri.cluster] (Quarkus Main Thread) Cluster created with settings {hosts=[localhost:27017], mode=SINGLE, requiredClusterType=UNKNOWN, serverSelectionTimeout='30000 ms'}
2021-03-07 12:26:40,617 INFO  [org.mon.dri.connection] (cluster-rtt-ClusterId{value='6044b870c8687d11c71dfb0b', description='null'}-localhost:27017) Opened connection [connectionId{localValue:1, serverValue:5}] to localhost:27017
2021-03-07 12:26:40,617 INFO  [org.mon.dri.connection] (cluster-ClusterId{value='6044b870c8687d11c71dfb0b', description='null'}-localhost:27017) Opened connection [connectionId{localValue:2, serverValue:6}] to localhost:27017
2021-03-07 12:26:40,617 INFO  [org.mon.dri.cluster] (cluster-ClusterId{value='6044b870c8687d11c71dfb0b', description='null'}-localhost:27017) Monitor thread successfully connected to server with description ServerDescription{address=localhost:27017, type=STANDALONE, state=CONNECTED, ok=true, minWireVersion=0, maxWireVersion=9, maxDocumentSize=16777216, logicalSessionTimeoutMinutes=30, roundTripTimeNanos=11510711}
2021-03-07 12:26:40,620 INFO  [org.mon.dri.connection] (cluster-ClusterId{value='6044b870c8687d11c71dfb0c', description='null'}-localhost:27017) Opened connection [connectionId{localValue:3, serverValue:8}] to localhost:27017
2021-03-07 12:26:40,620 INFO  [org.mon.dri.cluster] (cluster-ClusterId{value='6044b870c8687d11c71dfb0c', description='null'}-localhost:27017) Monitor thread successfully connected to server with description ServerDescription{address=localhost:27017, type=STANDALONE, state=CONNECTED, ok=true, minWireVersion=0, maxWireVersion=9, maxDocumentSize=16777216, logicalSessionTimeoutMinutes=30, roundTripTimeNanos=3728082}
2021-03-07 12:26:40,621 INFO  [org.mon.dri.connection] (cluster-rtt-ClusterId{value='6044b870c8687d11c71dfb0c', description='null'}-localhost:27017) Opened connection [connectionId{localValue:4, serverValue:7}] to localhost:27017
2021-03-07 12:26:40,704 INFO  [io.quarkus] (Quarkus Main Thread) foo-app 0.0.1-SNAPSHOT on JVM (powered by Quarkus 1.11.3.Final) started in 1.524s. Listening on: http://localhost:8080
2021-03-07 12:26:40,705 INFO  [io.quarkus] (Quarkus Main Thread) Profile dev activated. Live Coding activated.
2021-03-07 12:26:40,705 INFO  [io.quarkus] (Quarkus Main Thread) Installed features: [agroal, cdi, config-yaml, liquibase, mongodb-client, mongodb-panache, mongodb-rest-data-panache, mutiny, narayana-jta, resteasy, resteasy-jackson, smallrye-context-propagation, smallrye-openapi, swagger-ui]

所以quarkus知道liquibase,但是mongodb的变更集不会被执行。

Quarkus liquidbase扩展目前只针对JDBC数据源。

也许值得在我们的跟踪器中打开一个增强请求,以便我们跟踪这个需求,如果它还没有完成的话。

由于缺乏官方支持,最终采用自定义实现,这就是我所需要的:


import java.util.Optional;
import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.event.Observes;
import org.eclipse.microprofile.config.inject.ConfigProperty;
import io.quarkus.runtime.StartupEvent;
import liquibase.Liquibase;
import liquibase.database.Database;
import liquibase.database.DatabaseFactory;
import liquibase.ext.mongodb.database.MongoLiquibaseDatabase;
import liquibase.resource.ClassLoaderResourceAccessor;
import lombok.SneakyThrows;
@ApplicationScoped
public class MongoDBMigration {
@ConfigProperty(name = "quarkus.mongodb.connection-string")
String connectionString;
@ConfigProperty(name = "quarkus.mongodb.credentials.username")
Optional<String> username;
@ConfigProperty(name = "quarkus.mongodb.credentials.password")
Optional<String> password;
@ConfigProperty(name = "quarkus.liquibase.migrate-at-start")
boolean liquibaseEnabled;
@SneakyThrows
void onStart(@Observes StartupEvent ev) {
if (liquibaseEnabled) {
Database database = (MongoLiquibaseDatabase) DatabaseFactory.getInstance().openDatabase(connectionString, username.orElse(null), password.orElse(null), null, null);
Liquibase liquiBase = new Liquibase("db/changeLog.json", new ClassLoaderResourceAccessor(), database);
liquiBase.update("");
}
}
}

application.yaml:

quarkus:
mongodb:
connection-string: mongodb://localhost:27017/foo?socketTimeoutMS=1000&connectTimeoutMS=1000&serverSelectionTimeoutMS=1000
write-concern:
journal: false
database: foo
liquibase:
migrate-at-start: true
change-log: db/changeLog.xml

andbuild.gradle:

dependencies {
implementation "io.quarkus:quarkus-liquibase"
implementation "org.liquibase.ext:liquibase-mongodb:${liquibaseVersion}"
implementation "org.mongodb:mongodb-driver-sync:${mongodbVersion}"

最新更新