這篇文章主要介紹“怎么在springboot中集成hbase”,在日常操作中,相信很多人在怎么在springboot中集成hbase問題上存在疑惑,小編查閱了各式資料,整理出簡單好用的操作方法,希望對大家解答”怎么在springboot中集成hbase”的疑惑有所幫助!接下來,請跟著小編一起來學習吧!
創(chuàng)新互聯(lián)公司主營武勝網(wǎng)站建設的網(wǎng)絡公司,主營網(wǎng)站建設方案,重慶APP開發(fā)公司,武勝h5微信平臺小程序開發(fā)搭建,武勝網(wǎng)站營銷推廣歡迎武勝等地區(qū)企業(yè)咨詢
依賴:
<dependency> <groupId>org.springframework.data</groupId> <artifactId>spring-data-hadoop-hbase</artifactId> <version>2.5.0.RELEASE</version> </dependency> <dependency> <groupId>org.apache.hbase</groupId> <artifactId>hbase-client</artifactId> <version>1.1.2</version> </dependency> <dependency> <groupId>org.springframework.data</groupId> <artifactId>spring-data-hadoop</artifactId> <version>2.5.0.RELEASE</version> </dependency>
增加配置
官方提供的方式是通過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<Result> 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<Result> getListRowkeyData(String tableName, List<String> 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”的學習就結束了,希望能夠解決大家的疑惑。理論與實踐的搭配能更好的幫助大家學習,快去試試吧!若想繼續(xù)學習更多相關知識,請繼續(xù)關注創(chuàng)新互聯(lián)網(wǎng)站,小編會繼續(xù)努力為大家?guī)砀鄬嵱玫奈恼拢?/p>
當前名稱:怎么在springboot中集成hbase
鏈接地址:http://www.rwnh.cn/article2/pgssic.html
成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供微信公眾號、動態(tài)網(wǎng)站、網(wǎng)站建設、建站公司、外貿建站、網(wǎng)站收錄
聲明:本網(wǎng)站發(fā)布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經(jīng)允許不得轉載,或轉載時需注明來源: 創(chuàng)新互聯(lián)