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. 墨天轮沙龙 | Proxima 刘方:阿里巴巴大规模向量检索实时服务化引擎 Proxima SE

    导读 随着 AI 技术的广泛应用,以及数据规模的不断增长,向量检索也逐渐成了 AI 技术链路中不可或缺的一环. 在11月16日举办的[墨天轮数据库沙龙-向量数据库专场]邀请到阿里巴巴高级技术专家刘方, ...

  2. 墨天轮国产数据库沙龙 | 胡彦军:华为GaussDB迁移工具解密

    在共同推进国产化生态发展的进程下,墨天轮正式推出"墨天轮国产数据库沙龙"系列直播活动,将定期邀请各国产数据库产品专家.掌门人,共同探讨如何达成技术"自主可控"的 ...

  3. dotnet 使用自定义特性

    namespace TETTD.Common { /// <summary> /// 导入excel特性 标记字段映射的列 /// </summary> [AttributeU ...

  4. 常见函数 ,过滤函数 直接导入使用 ,filters.js 文件 批量注册过滤器

    // import parseTime, formatTime and set to filter /** * Show plural label if time is plural number * ...

  5. 7.flask 源码解析:session

    目录 一.flask 源码解析:session 1.1 session 简介 1.2 解析 1.2.1 请求过程 1.2.2 session 对象 1.2.3 签名算法 1.2.4 应答过程 1.3 ...

  6. 华为Ensp拓扑,使用MSTP、OSPF、DHCP、VRRP、链路聚合、CHAP

    OSPF+DHCP+VRRP+Eth-trunk+PPP(CHAP)+MSTP 实验目标: LSW1和LSW2核心交换机互为备份,配置链路聚合,设备冗余设计,LSW1和LSW2作为核心交换机配置DHC ...

  7. Machine Learning Week_4 Neural Networks: Representation

    目录 0 Neural Networks: Representation 1 Motivations 1.1 Non-linear Hypotheses 1.2 Neurons and the Bra ...

  8. docker容器开启ssh服务

    http://www.dtmao.cc/news_show_703007.shtml Step1 利用CentOS基础镜像,创建一个docker容器,主要这里要指定端口映射,必须要映射到容器内的22端 ...

  9. 循环程序结构设计(python)

    文章目录 1.基本概念 2.for循环 2.1 for循环基本结构 2.2 实例介绍 2.2.1 循环输出字符 2.2.2循环输出2000以内的素数 3.whlie循环 3.1 while循环基本结构 ...

  10. C++ 简易消息循环

    前言 本文将向大家介绍如何使用 C++ 的标准库实现一个异步和并发编程中都非常重要的编程模式:消息循环(Event Loop).尽管市面上存在不少库也提供了同样的功能,但有时候出于一些原因,我们并不想 ...