【问题标题】:MySQLPool used in Vert.x (Kotlin)Vert.x (Kotlin) 中使用的 MySQLPool
【发布时间】:2020-03-03 07:58:24
【问题描述】:

我目前正在基于 Vert.x(Kotlin) 构建项目,我需要连接到 MySQL 服务器。 Vert.x 提供了这个作为 MySQL 连接的解决方案 - https://vertx.io/docs/vertx-mysql-client/kotlin

我注意到有两种方法可以实现这一点。

// Connect options
var connectOptions = MySQLConnectOptions(
  port = 3306,
  host = "the-host",
  database = "the-db",
  user = "user",
  password = "secret")

// Pool options
var poolOptions = PoolOptions(
  maxSize = 5)

// Create the pooled client
var client = MySQLPool.pool(connectOptions, poolOptions)

还有

// Connect options
var connectOptions = MySQLConnectOptions(
  port = 3306,
  host = "the-host",
  database = "the-db",
  user = "user",
  password = "secret")

 // Pool options
 var poolOptions = PoolOptions(
     maxSize = 5)
 // Create the pooled client
 var client = MySQLPool.pool(vertx, connectOptions, poolOptions)

Vert.x 没有提到在什么情况下应该通过 vertx,有人知道吗?我们什么时候应该使用第二种实现方式?

【问题讨论】:

    标签: mysql kotlin vert.x vert.x-webclient


    【解决方案1】:

    如果您在非 Vert.x 线程上创建 MySQL 客户端(例如,在 Verticle 之外),则应该使用第二种实现。

    第一个实现将使用绑定到当前 Vert.x 线程的 Vert.x 实例(如果不是 Vert.x 线程则失败)

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-01-02
    • 1970-01-01
    • 2022-01-12
    • 1970-01-01
    • 1970-01-01
    • 2019-05-29
    • 2019-07-27
    相关资源
    最近更新 更多