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

x33g5p2x  于2021-12-20 转载在 其他  
字(2.4k)|赞(0)|评价(0)|浏览(192)

本文介绍如何使用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

相关文章