package com.be.edge.asset.source;

import io.vertx.core.AbstractVerticle;
import io.vertx.core.Promise;
import io.vertx.core.json.JsonObject;
import io.vertx.mysqlclient.MySQLConnectOptions;
import io.vertx.mysqlclient.MySQLPool;
import io.vertx.sqlclient.PoolOptions;
import io.vertx.sqlclient.Row;
import io.vertx.sqlclient.RowSet;
import lombok.extern.slf4j.Slf4j; @Slf4j
public class MySQLVerticle extends AbstractVerticle {
private MySQLPool client; @Override
public void start(Promise<Void> startPromise) throws Exception {
initMySQLPool();
/*
client.query("SELECT * FROM data_list WHERE id = 1")
.execute(ar -> {
if (ar.succeeded()) {
RowSet<Row> result = ar.result();
log.info("Got {} rows {}", result.size(), result);
} else {
log.info("Failure {}", ar.cause().getMessage());
}
client.close();
});
*/ client.getConnection().compose(conn -> {
// All operations execute on the same connection
return conn
.query("SELECT * FROM data_list WHERE id = 1")
.execute()
.compose(res -> conn
.query("SELECT * FROM data_list WHERE id = 2")
.execute())
.onComplete(ar -> {
// Release the connection to the pool
conn.close();
});
}).onComplete(ar -> {
if (ar.succeeded()) {
RowSet<Row> result = ar.result();
log.info("Got {} rows {}", result.rowCount(), result);
for (Row row : result) {
log.info("data {} {}", row.getInteger(0), row.getString(1));
}
} else {
System.out.println("Something went wrong " + ar.cause().getMessage());
}
});
} private void initMySQLPool() {
JsonObject config = config();
MySQLConnectOptions connectOptions = new MySQLConnectOptions(config.getJsonObject("connect"));
PoolOptions poolOptions = new PoolOptions(config.getJsonObject("pool"));
client = MySQLPool.pool(vertx, connectOptions, poolOptions);
}
}


initMySQLPool的更多相关文章

  1. 基于 Serverless Component 全栈解决方案

    什么是 Serverless Component Serverless Component 是 Serverless Framework 的,支持多个云资源编排和组织的场景化解决方案. Serverl ...

随机推荐

  1. 小程序的json文件

    json文件是页面的描述文件,对本页面的窗口外观设置,页面的配置可以覆盖全局的配置 (app.json);

  2. 17. ES6怎么嵌入变量

    模板字符串 具体操作: 首先 , 使用反引号包裹字符串,然后使用 ${} 嵌入变量 :

  3. day11-基本运算符

    运算符 java语言支持如下运算符: 优先级 ( 多敲,多练习 ) 算术运算符:+,-,*,/,%(模运算:取余),++,--  package operator; ​ public class De ...

  4. Linux基础-查看和设置环境变量

    一,查看环境变量 二,环境变量类型 三,设置环境变量 四,参考资料 一,查看环境变量 在 Linux中,环境变量是一个很重要的概念.环境变量可以由系统.用户.Shell 以及其他程序来设定,其是保存在 ...

  5. 微信小程序、uniapp、vue生命周期钩子函数

    生命周期是指从创建到销毁的过程 一.微信小程序 小程序里面有两种生命周期函数,第一个:通过App()来注册一个小程序 ,第二个:通过Page()来注册一个页面 应用生命周期函数   app( ) ap ...

  6. linux 排查项目问题常用命令

    查看日志 头部开始查询文件file.log前100中包含'测试'的记录前后一行,并形成文件为new.loghead -n 100 file.log|grep -1 '测试' > new.log ...

  7. CF716B Complete the Word 题解

    CF716B Complete the Word 题解 分析 首先观察数据范围是 \(50000\),可以考虑 \(O(n)\) 暴力. 在字符串中枚举子串开始的位置 \(i\),然后再枚举 \(i\ ...

  8. PbRL | Christiano 2017 年的开山之作,以及 Preference PPO / PrefPPO

    PrefPPO 首次(?)出现在 PEBBLE,作为 pebble 的一个 baseline,是用 PPO 复现 Christiano et al. (2017) 的 PbRL 算法. For eva ...

  9. Nuxt.js 应用中的 webpack:compile 事件钩子

    title: Nuxt.js 应用中的 webpack:compile 事件钩子 date: 2024/11/22 updated: 2024/11/22 author: cmdragon excer ...

  10. cornerstone中raft_server源码解析

    1.概述 cornerstone中核心即为raft_server的实现. 在raft里面有follower,leader,candidate三种角色,且角色身份还可以相互切换. 写三个类followe ...