1. 创建 hbase 连接池

  1. import org.apache.hadoop.conf.Configuration
  2. import org.apache.hadoop.hbase.client.{Connection, ConnectionFactory}
  3. import org.apache.hadoop.hbase.HBaseConfiguration
  4. import org.slf4j.{Logger, LoggerFactory}
  5. object HbaseConnectionPool {
  6. private var conn: Connection = _
  7. private var index: Int = _
  8. private val logger: Logger = LoggerFactory.getLogger(this.getClass)
  9. def getConnection: Connection = {
  10. if (conn == null) {
  11. this.synchronized {
  12. if (conn == null) {
  13. createConnection()
  14. }
  15. }
  16. }
  17. conn
  18. }
  19. private def createConnection(): Unit = {
  20. index += 1
  21. logger.warn(s"------------hbase connection created for the ${index} time ---------------")
  22. val hbaseConf: Configuration = HBaseConfiguration.create()
  23. hbaseConf.set("hbase.zookeeper.quorum", "hbase01:2181")
  24. hbaseConf.set("zookeeper.znode.parent", "/hbase")
  25. //hbaseConf.set("hbase.zookeeper.property.clientPort", "2181")
  26. conn = ConnectionFactory.createConnection(hbaseConf)
  27. }
  28. }

https://blog.csdn.net/ycf921244819/article/details/81706119