Vertx是一個高效的異步框架,支持Java、Scala、JavaScript、Kotlin等多種語言。在非性能調優的場景下,TPS能夠高達2-3萬,同時,支持多種數據源也提供了異步支持。mysql
大數據的同窗確定對其很瞭解,是Apache基金會下的頂級工程,Phoenix幫助Hbase提供了SQL語法的支持,讓難用的Hbase變得簡單易用。sql
在項目應用中,爲了達到簡單、高效的接口化查詢功能。apache
只對涉及Phoenix方面進行講解,經過Scala進行編寫
<dependency> <groupId>io.vertx</groupId> <artifactId>vertx-mysql-postgresql-client</artifactId> </dependency> <dependency> <groupId>io.vertx</groupId> <artifactId>vertx-jdbc-client</artifactId> </dependency> <dependency> <groupId>org.apache.phoenix</groupId> <artifactId>phoenix-core</artifactId> <version>4.13.1-HBase-1.3</version> </dependency>
class HbaseDatabase(vertx: Vertx, dbConfig: DBInfoEntity, queryTimeout: Long) extends AbstractDatabase(vertx, dbConfig, queryTimeout) with LazyLogging { var hbaseClient: JDBCClient = _ init(vertx, dbConfig, queryTimeout) override def init(vertx: Vertx, dbConfig: DBInfoEntity, queryTimeout: Long): Unit = { val HbaseClientConfig: JsonObject = new JsonObject() .put("url", dbConfig.getHost) .put("user", "") .put("password", "") .put("max_idle_time", queryTimeout) .put("driver_class", "org.apache.phoenix.jdbc.PhoenixDriver") this.hbaseClient = JDBCClient.createShared(vertx, HbaseClientConfig) } override def action(bodyInformation: BodyInformationVO, callback: Resp[Object] => Unit): Unit = { hbaseClient.getConnection(new Handler[AsyncResult[SQLConnection]]() { override def handle(res: AsyncResult[SQLConnection]): Unit = { if (res.succeeded()) { val connection = res.result() connection.query(bodyInformation.command, new Handler[AsyncResult[ResultSet]]() { override def handle(result: AsyncResult[ResultSet]): Unit = { if (result.succeeded()) { setMetaData(result.result().getColumnNames, CacheContainer.getMetadatas) callback(Resp.success(result.result().getRows())) } else { logger.error("Get HBase value is error", result.cause()) callback("Get HBase value is error") } } }) } else { logger.error("Get HBase connect is error", res.cause()) callback("Get HBase connect is error") } } }) }
jdbc:phoenix:host1,host2:2181:/hbase