千家信息网

怎么在springboot中集成hbase

发表于:2025-01-18 作者:千家信息网编辑
千家信息网最后更新 2025年01月18日,这篇文章主要介绍"怎么在springboot中集成hbase",在日常操作中,相信很多人在怎么在springboot中集成hbase问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对
千家信息网最后更新 2025年01月18日怎么在springboot中集成hbase

这篇文章主要介绍"怎么在springboot中集成hbase",在日常操作中,相信很多人在怎么在springboot中集成hbase问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答"怎么在springboot中集成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方式,简单改写后如下:

@Configurationpublic 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@Slf4jpublic class HBaseService {    @Autowired  private HbaseTemplate hbaseTemplate;    public List getRowKeyAndColumn(String tableName, String startRowkey, String stopRowkey, String column, String qualifier) {    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.toBytes(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.stream().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());  }}

到此,关于"怎么在springboot中集成hbase"的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注网站,小编会继续努力为大家带来更多实用的文章!

0