简单写一个scala获取hbase 连接方法
/**
* HBase工具类
*/
import org.apache.hadoop.hbase.client.{BufferedMutator, Connection, ConnectionFactory, Put}
import org.apache.hadoop.hbase.util.Bytes
import org.apache.hadoop.hbase.{HBaseConfiguration, TableName}
import java.util.concurrent.Executors
object HBaseUtils {
val myConf = HBaseConfiguration.create()
/**
* 获取Hbase连接
*
* @return
*/
def getHbaseConn(): Connection = {
// val hbaseConn = ConnectionFactory.createConnection(myConf);
// val mutator = hbaseConn.getBufferedMutator(TableName.valueOf("tableName"))
myConf.set("hbase.zookeeper.quorum", "192.168.1.31,192.168.1.32,192.168.1.13")
myConf.set("hbase.zookeeper.property.clientPort", "2181")
myConf.set("hbase.regionserver.thread.compaction.large", "5")
myConf.set("hbase.regionserver.thread.compaction.small", "5")
// myConf.set("hbase.hregion.majorcompaction","0")
myConf.set("hbase.hstore.compaction.min", "10")
myConf.set("hbase.hstore.compaction.max", "10")
myConf.set("hbase.hstore.blockingStoreFiles", "100")
myConf.set("hbase.hstore.compactionThreshold", "7")
myConf.set("hbase.regionserver.handler.count", "100")
myConf.set("hbase.regionserver.hlog.splitlog.writer.threads", "10")
myConf.set("hbase.regionserver.thread.compaction.small", "5")
myConf.set("hbase.regionserver.thread.compaction.large", "8")
myConf.set("hbase.hregion.max.filesizes", "4G")
myConf.set("hbase.hregion.max.filesize", "60G")
myConf.set("hbase.hregion.memstore.flush.size", "60G")
myConf.set("hbase.hregion.memstore.block.multiplier", "5")
// myConf.set("hbase.client.write.buffer", "8388608")
myConf.set("hbase.client.pause", "200")
myConf.set("hbase.client.retries.number", "71")
myConf.set("hbase.ipc.client.tcpnodelay", "false")
myConf.set("hbase.client.scanner.caching", "500")
myConf.set("hbase.htable.threads.max", Integer.MAX_VALUE.toString)
myConf.set("hbase.htable.threads.keepalivetime", "60")
val threadPool = Executors.newFixedThreadPool(Runtime.getRuntime()
.availableProcessors())
ConnectionFactory.createConnection(myConf, threadPool)
// ConnectionFactory.createConnection(myConf)
}
}