基于springboot集成hbase過程解析
這篇文章主要介紹了基于springboot集成hbase過程解析,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下
springboot-habse:
https://github.com/spring-projects/spring-hadoop-samples/tree/master/hbase
依賴:
<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()); } }
以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
相關文章
java獲取redis日志信息與動態(tài)監(jiān)控信息的方法
這篇文章主要給大家介紹了關于java如何獲取redis日志信息與動態(tài)監(jiān)控信息的方法,文中介紹的非常詳細,對大家具有一定的參考價值,需要的朋友們下面來一起看看吧。2017-04-04SpringBoot使用CORS實現(xiàn)無縫跨域的方法實現(xiàn)
CORS 是一種在服務端設置響應頭部信息的機制,允許特定的源進行跨域訪問,本文主要介紹了SpringBoot使用CORS實現(xiàn)無縫跨域的方法實現(xiàn),具有一定的參考價值,感興趣的可以了解一下2023-10-10關于WeakhashMap與HashMap之間的區(qū)別和聯(lián)系
這篇文章主要介紹了關于WeakhashMap與HashMap之間的區(qū)別和聯(lián)系,WeakHashMap從名字可以得知主要和Map有關,不過還有一個Weak,我們就更能自然而然的想到這里面還牽扯到一種弱引用結構,因此想要徹底搞懂,我們還需要知道四種引用,需要的朋友可以參考下2023-09-09Java?Controller實現(xiàn)參數(shù)驗證與統(tǒng)一異常處理流程詳細講解
Controller是Spring接受并處理網(wǎng)頁請求的組件,是整個應用的入口,因此學會Controller的常用注解對理解一個應用是重中之重。SpringBoot的Controller中經(jīng)常會用到注解@Controller、@RestController、@RequestMapping、@RequestBody等2023-01-01