加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

disconf-基于xml分布式配置管理hbase

发布时间:2020-12-16 08:44:44 所属栏目:百科 来源:网络整理
导读:本文介绍如何使用disconf管理hbase的配置 新建hbase.properties,内容为: # hbase config hbase.quorum = ip hdfs.namenode.host =ip hdfs.namenode.port = 8020 hbase.contrast.trans.table = contrast_trans 新建hbase.xml,内容为: ? xml version= "1.0
本文介绍如何使用disconf管理hbase的配置
新建hbase.properties,内容为:
# hbase config
hbase.quorum=ip
hdfs.namenode.host=ip
hdfs.namenode.port=8020
hbase.contrast.trans.table=contrast_trans
新建hbase.xml,内容为:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xmlns:p="http://www.springframework.org/schema/p" xmlns:c="http://www.springframework.org/schema/c"
xmlns:hdp="http://www.springframework.org/schema/hadoop"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/hadoop
http://www.springframework.org/schema/hadoop/spring-hadoop.xsd">


<hdp:configuration id="hadoopConfiguration">
fs.default.name=hdfs://${hdfs.namenode.host}:${hdfs.namenode.port}
</hdp:configuration>

<hdp:hbase-configuration id="hbaseConfiguration" stop-proxy="false" delete-connection="false">
hbase.zookeeper.quorum=${hbase.quorum}
</hdp:hbase-configuration>

<bean id="hbaseTemplate" class="org.springframework.data.hadoop.hbase.HbaseTemplate"
p:configuration-ref="hbaseConfiguration" p:autoFlush="true" />
</beans>
主要使用的是spring data hbase,注入hbaseTemplate就可以使用hbase的api

我们公司的业务中有个需求,hbase新导入数据一般重新放在一个表中,所以在查询的时候需要用接口去主动改变表名,利用disconf我们就不需要了,我们在配置文件中有一个配置hbase.contrast.trans.table,我们可以用DisconfFileItem来管理一个变量,如下:
@Service
@DisconfFile(filename = "hbase.properties")
public class HbaseService {

@Autowired
private HbaseTemplate hbaseTemplate;

private String ctTable;

public ContrastTrans find() {
return this.hbaseTemplate.get(this.ctTable,"13_1449289660000_34353c8f-5149-4140-9b13-673588978024",GlobalConstant.COLUMN_FAMILY,new ContrastTransRowMapper());
}

@DisconfFileItem(name = "hbase.contrast.trans.table",associateField = "ctTable")
public String getCtTable() {
return ctTable;
}

public void setCtTable(String ctTable) {
this.ctTable = ctTable;
}
}
这样的话在disconf-web中配置好了就能立即生效改变ctTable的值,可以实现切表。

参考: https://github.com/knightliao/disconf/wiki

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读