Vertx-Phoenix实践
发布时间:2020-12-16 09:41:39 所属栏目:安全 来源:网络整理
导读:Vertx-Phoenix实践 前言 Vertx Vertx是一个高效的异步框架,支持Java、Scala、JavaScript、Kotlin等多种语言。在非性能调优的场景下,TPS可以高达2-3万,同时,支持多种数据源也提供了异步支持。 Phoenix 大数据的同学肯定对其很了解,是Apache基金会下的顶
Vertx-Phoenix实践前言VertxVertx是一个高效的异步框架,支持Java、Scala、JavaScript、Kotlin等多种语言。在非性能调优的场景下,TPS可以高达2-3万,同时,支持多种数据源也提供了异步支持。 Phoenix大数据的同学肯定对其很了解,是Apache基金会下的顶级工程,Phoenix帮助Hbase提供了SQL语法的支持,让难用的Hbase变得简单易用。 场景出发点目标在项目应用中,为了达到简单、高效的接口化查询功能。 现状
问题与方案
Vertx-Phoenix实现只对涉及Phoenix方面进行讲解,通过Scala进行编写 依赖Pom<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,queryTimeout) override def init(vertx: Vertx,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") } } }) } 相关配置说明URL格式jdbc:phoenix:host1,host2:2181:/hbase (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |