Postgresql Vert.x JOOQ RxJava Postgres顺序数据库调用
我将Vert.x和JOOQ与rx async选项一起使用: 我有一个HTTP垂直链接,它将/jooqtest路由到用Kotlin编写的jooqRxAsyncHandler:Postgresql Vert.x JOOQ RxJava Postgres顺序数据库调用,postgresql,kotlin,rx-java2,vert.x,jooq,Postgresql,Kotlin,Rx Java2,Vert.x,Jooq,我将Vert.x和JOOQ与rx async选项一起使用: 我有一个HTTP垂直链接,它将/jooqtest路由到用Kotlin编写的jooqRxAsyncHandler: private fun jooqRxAsyncHandler(context: RoutingContext) { val jooqConfig: Configuration = DefaultConfiguration().set(SQLDialect.POSTGRES) val dbCredential
private fun jooqRxAsyncHandler(context: RoutingContext) {
val jooqConfig: Configuration = DefaultConfiguration().set(SQLDialect.POSTGRES)
val dbCredentials = JsonObject()
.put("host", "localhost")
.put("username", "username")
.put("password", "password")
.put("database", "dbname")
dbClient = PostgreSQLClient.createNonShared(vertx, dbCredentials)
val dao = UserDao(jooqConfig, dbClient)
println("getting. client: " + dbClient)
dao.deleteByCondition(USER.EMAIL.eq("f@g.com"))
.concatWith(
dao.insert(User("f@g.com",
"f@g.com",
"accessToken",
OffsetDateTime.now(),
"f@g.com"))
)
.subscribe()
dao.findOneByCondition(USER.EMAIL.eq("test@test.com.zz"))
.doOnEvent { something, x ->
if (x == null) {
context.response().putHeader("content-type", "text/html").end("JOOQ test $something")
} else {
System.err.println("Something failed badly: " + x.message)
context.response().putHeader("content-type", "text/html").end("JOOQ error")
}
}
.subscribe()
println("done")
}
两个问题:
1这是顺序触发还是并行触发,我如何让所有东西按顺序触发删除、插入、选择
2当发出.subscribe调用时,这会阻止主线程吗?请在Clement Escoffier的帮助下回答: 1两个。订阅同时调用fire。delete和insert调用与.concatWith按顺序组合使用 2这是非阻塞的 另外,要按顺序运行delete、insert和findByOne调用,请使用.ignoreElement和.and,如下所示:
private fun jooqRxAsyncHandler(context: RoutingContext) {
val jooqConfig: Configuration = DefaultConfiguration().set(SQLDialect.POSTGRES)
val dbCredentials = JsonObject()
.put("host", "localhost")
.put("username", "username")
.put("password", "password")
.put("database", "dbname")
dbClient = PostgreSQLClient.createNonShared(vertx, com.datadeploytool.database.dbCredentials)
val dao = UserDao(jooqConfig, dbClient)
println("getting. client: $dbClient")
dao.deleteByCondition(USER.EMAIL.eq("f@g.com")).ignoreElement()
.andThen(
dao.insert(User("f@g.com",
"f@g.com",
"accessToken",
OffsetDateTime.now(),
"f@g.com"))
).ignoreElement()
.andThen(
dao.findOneByCondition(USER.EMAIL.eq("test@test.com.zz"))
)
.doOnEvent { something, x ->
if (x == null) {
context.response().putHeader("content-type", "text/html").end("JOOQ test $something")
} else {
System.err.println("Something failed badly: " + x.message)
context.response().putHeader("content-type", "text/html").end("JOOQ error")
}
}
.subscribe()
println("done")
}