基于springboot集成hbase过程解析

网友投稿 481 2023-07-03

基于springboot集成hbase过程解析

基于springboot集成hbase过程解析

这篇文章主要介绍了基于springboot集成hbase过程解析,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下

springboot-habse:

https://github.com/spring-projects/spring-hadoop-samples/tree/master/hbase

依赖:

org.springframework.data

spring-data-hadoop-hbase

2.5.0.RELEASE

org.apache.hbase

hbase-client

1.1.2

org.springframework.data

spring-data-hadoop

2.5.0.RELEASE

增加配置

官方提供的方式是通过xml方式,简单改写后如下:

@Configuration

public class HBaseConfiguration {

@Value("${hbase.zookeeper.quorum}")

private String zookeeperQuorum;

@Value("${hbase.zookeeper.property.clientPort}")

private String clientPort;

@Value("${zookeeper.znode.parent}")

private String znodeParent;

@Bean

public HbaseTemplate hbaseTemplate() {

org.apache.hadoop.conf.Configuration conf = new org.apache.hadoop.conf.Configuration();

conf.set("hbase.zookeeper.quorum", zookeeperQuorum);

conf.set("hbase.zookeeper.property.clientPort", clientPort);

conf.set("zookeeper.znode.parent", znodeParent);

return new HbaseTemplate(conf);

}

}

application.yml:

hbase:

zookeeper:

quorum: hadoop001,hadoop002,hadoop003

property:

clientPort: 2181

zookeeper:

znode:

parent: /hbase

HbaseTemplate test :

@Service

@Slf4j

public class HBaseService {

@Autowired

private HbaseTemplate hbaseTemplate;

public List getRowKeyAndColumn(String tableName, String startRowkey, String stopRowkey, String column, String quDCnVjalifier) {

FilterList filterList = new FilterList(FilterList.Operator.MUST_PASS_ALL);

if (StringUtils.isNotBlank(column)) {

log.debug("{}", column);

filterList.addFilter(new FamilyFilter(CompareFilter.CompareOp.EQUAL, new BinaryComparator(Bytes.toByteDCnVjs(column))));

}

if (StringUtils.isNotBlank(qualifier)) {

log.debug("{}", qualifier);

filterList.addFilter(new QualifierFilter(CompareFilter.CompareOp.EQUAL, new BinaryComparator(Bytes.toBytes(qualifier))));

}

Scan scan = new Scan();

if (filterList.getFilters().size() > 0) {

scan.setFilter(filterList);

}

scan.setStartRow(Bytes.toBytes(startRowkey));

scan.setStopRow(Bytes.toBytes(stopRowkey));

return hbaseTemplate.find(tableName, scan, (rowMapper, rowNum) -> rowMapper);

}

public List getListRowkeyData(String tableName, List rowKeys, String familyColumn, String column) {

return rowKeys.sthttp://ream().map(rk -> {

if (StringUtils.isNotBlank(familyColumn)) {

if (StringUtils.isNotBlank(column)) {

return hbaseTemplate.get(tableName, rk, familyColumn, column, (rowMapper, rowNum) -> rowMapper);

} else {

return hbaseTemplate.get(tableName, rk, familyColumn, (rowMapper, rowNum) -> rowMapper);

}

}

return hbaseTemplate.get(tableName, rk, (rowMapper, rowNum) -> rowMapper);

}).collect(Collectors.toList());

}

}

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:springboot跨域CORS处理代码解析
下一篇:SpringBoot登录判断过程代码实例
相关文章

 发表评论

暂时没有评论,来抢沙发吧~