spring+hbase集成
来源:互联网 发布:o 数据库管理软件 编辑:程序博客网 时间:2024/06/05 00:21
1. 引入maven依赖
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-hadoop</artifactId>
<version>1.0.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.apache.hbase</groupId>
<artifactId>hbase</artifactId>
<version>0.94.12</version>
</dependency>
2. Spring-data头部命名空间和标签
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:hdp="http://www.springframework.org/schema/hadoop"
xsi:schemaLocation="
http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/hadoophttp://www.springframework.org/schema/hadoop/spring-hadoop.xsd">
3. 配置hbase基础信息
//配置hadoop的基本信息
<hdp:configuration>
fs.default.name=hdfs://172.20.59.47:9000 </hdp:configuration>
//配置zookeeper的信息,远程连接hbase时使用
<hdp:hbase-configuration zk-quorum="xxx.xxx.xxx.xxx"zk-port="2181"/>
<beanid="htemplate"class="org.springframework.data.hadoop.hbase.HbaseTemplate" >
<property name="configuration"ref="hbaseConfiguration">
</property>
</bean>
hbaseConfiguration其实就是指的<hdp:hbase-configuration/>配置的信息
4. 实例演示
public static void main(String[] args) {
ApplicationContext context = new ClassPathXmlApplicationContext(newString[] { "spring-beans-hbase.xml" });
BeanFactory factory = (BeanFactory) context;
HbaseTemplate htemplate = (HbaseTemplate) factory.getBean("htemplate");
String custom = "custom";
htemplate.get("wcm", "10461", newRowMapper<String>(){
@Override
public String mapRow(Result result, int rowNum) throws Exception {
// TODO Auto-generated methodstub
for(KeyValue kv :result.raw()){
String key = newString(kv.getQualifier());
String value = newString(kv.getValue());
System.out.println(key +"= "+Bytes.toString(value.getBytes()));
}
return null;
}
});
}
查看数据 get “wcm“, ”rowkey“ 得到一条数据
5. 基本命令
查看有哪些表list
查看所有数据 scan “表名”
查看数据 get “wcm“,”lrowkey“ 得到一条数据
删除一条数据delete “表名”,”主键”,”列族”,”列”
删除整条数据deleteAll “表名”,”主键”
Hbase的特点:
>>在命令窗口只能一次更新一个单元格;
>>在程序中通过调用HTable.setAutoFlush(false)方法可以将HTable写客户端的自动flush关闭,这样可以批量写入数据到 HBase,而不是有一条put就执行一次更新,只有当put填满客户端写缓存时,才实际向HBase服务端发起写请求。默认情况下auto flush是开启的。
参考文档:
http://docs.spring.io/springhadoop/docs/1.0.1.RELEASE/reference/html/hbase.html
http://abloz.com/hbase/book.html
- spring+hbase集成
- 关于spring集成hbase
- 关于spring集成hbase
- spring+hbase集成
- Spring Boot 集成MyBatis 访问Hbase-Phoenix
- 集成hbase
- spring集成hbase以及所遇到的问题
- Hive与HBase集成
- Hbase与eclipse集成
- hive 集成hbase 笔记
- hive集成hbase笔记
- Hive与HBase集成
- 集成Lucene和HBase
- hive与hbase集成
- hive集成hbase
- hive与hbase集成
- hive与hbase集成
- hive与hbase集成
- 硬盘被损坏后怎么恢复文件
- 黑马程序员—Java基础加强 (基本数据的自动拆装箱及享元设计模式)
- 小游戏 Untrusted 推荐及攻略
- Java GUI编程(七)
- Java日期格式化及其使用例子收集
- spring+hbase集成
- java二维码生成与解析代码实现
- OpenGL: Accumulation Buffer(累积缓存)
- mysql:Table './xdb/auditlog' is marked as crashed and should be repaired
- fgetc
- A. Password Check
- Android 夸进程通信 AIDL
- qemu kvm 安装及使用教程
- Django是怎么处理请求的