Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to integrate hbase in springboot

2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces "how to integrate hbase in springboot". In daily operation, I believe many people have doubts about how to integrate hbase in springboot. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the questions of "how to integrate hbase in springboot". Next, please follow the editor to study!

Dependence:

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

Increase configuration

The official method is through xml. After a simple rewrite, it is as follows:

@ 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);}) .integration (Collectors.toList ());}} at this point, the study on "how to integrate hbase in springboot" is over, hoping to solve everyone's doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report