Java通过thrift连接hbase
1.安装thrift依赖包
使用root登陆linux, 1.1执行指令:
yum -y install automake libtool flex bison pkgconfig gcc-c++ boost-devel libevent-devel zlib-devel python-devel ruby-devel openssl-devel 结果如下图所示:
1.2执行指令 sudo
curl ftp://http://doc.guandang.net/mirror/ftp5.gwdg.de/pub/opensuse/repositories/home:/monkeyiq:/centos6updates/CentOS_CentOS-6/noarch/autoconf-2.69-12.2.noarch.rpm > autoconf-2.69-12.2.noarch.rpm 结果如下图所示:
1.3执行指令
yum -y install autoconf-2.69-12.2.noarch.rpm 结果如下图所示:
1.4执行指令 yum -y install git 结果如下:
2.安装thrift
使用hadoop
用户登陆linux 2.1 执行指令
git clone https://http://doc.guandang.net/repos/asf/thrift.git
2.2执行指令 cd thrift
git checkout -b thrift-0.9.1 0.9.1
2.3执行指令
./bootstrap.sh
2.4执行指令
./configure
2.5执行指令 make
2.6修改 /etc/sudoers,增加用户hadoop的配置
2.7执行指令
sudo make install
2.8执行指令
thrift –version
3.创建java api 3.1 下载 hbase源代码 版本为 hbase-0.96.2-src.tar.gz 将当前目录切换到
$HBASE_HOME/hbase-thrift/src/main/resources/org/apache/hadoop/hbase/thrift 执行指令
thrift --gen java Hbase.thrift
3.2 启动
hbase thrift
服务 hbase thrift -p 9090 start
3.3.得到libthrift-0.9.1.jar
进入 /home/hadoop/thrift/lib/java 运行 ant
进入 /home/hadoop/thrift/lib/java/build 得到 libthrift-0.9.1.jar 如下图所示:
3.4 下载 slf4j-api-1.7.7.jar 和 slf4j-jdk14-1.7.7.jar 下载地址 http://doc.guandang.net/download.html
3.5 创建工程 chapter15 导入 3.3 和 3.4 步骤得到的 jar 包
AbstractHBaseThriftService.java 文件
package cn.dataguru.hadoop.hbase.thrift; import java.util.List; import java.util.Map; import org.apache.hadoop.hbase.thrift.generated.Hbase; import org.apache.hadoop.hbase.thrift.generated.TRowResult; import org.apache.thrift.TException; import org.apache.thrift.protocol.TBinaryProtocol; import org.apache.thrift.protocol.TProtocol; import org.apache.thrift.transport.TSocket; import org.apache.thrift.transport.TTransport;
import org.apache.thrift.transport.TTransportException; public abstract class AbstractHBaseThriftService { protected static final String CHARSET = "UTF-8"; private String host = "localhost"; private int port = 9090; private final TTransport transport; protected final Hbase.Client client; public AbstractHBaseThriftService() { transport = new TSocket(host, port); TProtocol protocol = new TBinaryProtocol(transport, true, true); client = new Hbase.Client(protocol); } public AbstractHBaseThriftService(String host, int port) { super(); transport = new TSocket(host, port); TProtocol protocol = new TBinaryProtocol(transport, true, true); client = new Hbase.Client(protocol); } public void open() throws TTransportException { if(transport != null) { transport.open(); } } public void close() { if(transport != null) { transport.close(); } }
public abstract List<String> getTable
s() throws TException;
public abstract void update(String table, String rowKey, boolean writeT oWal, String fieldName, String fieldValue, Map<String, String> attributes) throws TException; public abstract void update(String table, String rowKey, boolean writeT oWal, Map<String, String> fieldNameValues, Map<String, String> attributes) throws TException;
public abstract void deleteCell(String table, String rowKey, boolean wr iteToWal, String column, Map<String, String> attributes) throws TException; public abstract void deleteCells(String table, String rowKey, boolean w riteToWal, List<String> columns, Map<String, String> attributes) throws TExcepti on;
public abstract void deleteRow(String table, String rowKey, Map<String, String> attributes) throws TException;
public abstract int scannerOpen(String table, String startRow, List<Str ing> columns, Map<String, String> attributes) throws TException; public abstract int scannerOpen(String table, String startRow, String s topRow, List<String> columns, Map<String, String> attributes) throws TException; public abstract int scannerOpenWithPrefix(String table, String startAnd Prefix, List<String> columns, Map<String, String> attributes) throws TException; public abstract int scannerOpenTs(String table, String startRow,
List<String> columns, long timestamp, Map<String, String> attri butes) throws TException; public abstract int scannerOpenTs(String table, String startRow, String stopRow, List<String> columns, long timestamp, Map<String, String> attri butes) throws TException;
public abstract List<TRowResult> scannerGetList(int id, int nbRows) thr ows TException; public abstract List<TRowResult> scannerGet(int id) throws TException;
public abstract List<TRowResult> getRow(String table, String row, Map<String, String> attributes) throws TException; public abstract List<TRowResult> getRows(String table, List<String> rows, Map<String, String> attributes) throws T Exception; public abstract List<TRowResult> getRowsWithColumns(String table, List<String> rows, List<String> columns, Map<String, Strin g> attributes) throws TException;
public abstract void scannerClose(int id) throws TException;
/** * Iterate result rows(just for test purpose) * @param result */ public abstract void iterateResults(TRowResult result); }
HBaseThriftClient.java
package cn.dataguru.hadoop.hbase.thrift; import java.io.UnsupportedEncodingException; import java.nio.ByteBuffer; import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java …… 此处隐藏:8842字,全部文档内容请下载后查看。喜欢就下载吧 ……
相关推荐:
- [政务民生]2013年公共基础知识热点问题(七)
- [政务民生]检验检测机构资质认定评审准则及释义20
- [政务民生]关于印发重庆市房屋建筑和市政基础设施
- [政务民生]1、隧道洞身开挖支护施工技术交底书
- [政务民生]2015年山东省17地市中考语文试题分类汇
- [政务民生]2-高级会计师资格考试和评审流程图
- [政务民生]2018版中国清分机行业发展分析及前景策
- [政务民生]新课改高中政治探究
- [政务民生]2018-2024年中国新型组合房屋行业投资
- [政务民生]2015年上海市春季高考数学模拟试卷五
- [政务民生]灌砂法及环刀法测压实度(带计算过程)
- [政务民生]运筹学实验2求解非线性规划
- [政务民生]劝学、逍遥游默写(教师卷)
- [政务民生]《运筹学》 - 期末考试 - 试卷A - 答案
- [政务民生]八年级英语下册 Module 6 Hobbies测试
- [政务民生]2019年宪法知识竞赛试题库100题(含答
- [政务民生]自动化英文文献翻译
- [政务民生]公文格式实施细则
- [政务民生]高一地理上册课堂跟踪练习题6
- [政务民生]会计继续教育习题及答案
- 第三章 无约束最优化方法
- 泛读教程第三册答案
- 魏晋南北朝文学
- 幂的运算复习题
- 城市环境问题的成因与治理策略_以社会
- 钢结构行业产业链及竞争分析研究
- 新型热塑性弹性体增韧聚丙烯的研究
- 中国旅游地理B卷试题及答案
- (苏教版)五年级数学上册第三单元测试卷
- 不稳定性心绞痛诊断与治疗
- 俞氏国际后勤职能部门绩效考核办法
- GB7258-2017新标准考试题含答案
- 小学生汉字听写比赛活动方案
- 1.3《平抛运动》学案 教科版必修2
- 2011香港特别行政区公务员考试复习资料
- 考虑水力条件变化的城市给水管网可靠性
- 表面活性剂在油田开发和生产中的应用
- ITT内部培训资料-FI端吸泵的介绍
- 文明守纪,从我做起学生发言稿
- 初中读《聊斋志异》心得体会800字范文




