1

I am currently working on a project build based on Vert.x(Kotlin) and I need to connect to MySQL server. Vert.x provides this as the solution for the MySQL connection - https://vertx.io/docs/vertx-mysql-client/kotlin

I noticed that there are two approaches to implement this.

// 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)

And

// 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 dose not mention that under what kind of situation we should pass vertx, does anyone know about this? when we should use the second implementation?

zhianABCD
  • 223
  • 1
  • 4
  • 15

1 Answers1

2

You should use the second implementation if you create the MySQL client on a non-Vert.x thread (e.g. out of a verticle).

The first implementation will use the Vert.x instance bound to the current Vert.x thread (or fail if it's not a Vert.x thread)

tsegismont
  • 8,591
  • 1
  • 17
  • 27
  • please, can You run your eyes on https://stackoverflow.com/questions/64885819/io-vertx-mysqlclient-mysqlpool-query-execute-is-never-really-executed-and-r and tell me why the insert is never executed? (I followed you recomendation above) – Jim C Nov 23 '20 at 23:32