Skip to content
Published on

HBase Client API Basics

Authors
  • Name
    Twitter

Overview

Let's explore the types of HBase Client APIs used to interact with HBase.

HBase Client Download

hbase-maven-link

By visiting this link HBase Client Maven Download Link, you can find the Maven repository for adding the HBase Client to your pom.xml.

Connection Setup

pom.xml

If you have set up your project with Maven, you can add the dependency to pom.xml as shown below. HBase Client version 2.5.2 was selected.

pom.xml
    <dependencies>
        <dependency>
            <groupId>org.apache.hbase</groupId>
            <artifactId>hbase</artifactId>
            <version>2.5.2</version>
        </dependency>
        <dependency>
            <groupId>org.apache.hbase</groupId>
            <artifactId>hbase-client</artifactId>
            <version>2.5.2</version>
        </dependency>
    </dependencies>

Preparing hbase-site.xml

To use HBase, the process needs to know the HBase server information. Since HBase cluster metadata is managed through Zookeeper, you only need the Zookeeper quorum information. There are two methods for this, and we will look at both.

  1. Dynamically create a configuration containing the Zookeeper Quorum information.
  2. Add hbase-site.xml to the class-path.

Manually entering zookeeper quorum information

        Configuration config = HBaseConfiguration.create();
        config.set("hbase.zookeeper.quorum", "ubuntu01,ubuntu02,ubuntu03");
        Connection conn =ConnectionFactory.createConnection(config);
        Table table = conn.getTableBuilder(TableName.valueOf("default","testtable"), null).build();
        HTableDescriptor ds =  table.getTableDescriptor();
        System.out.println(ds.getNameAsString());

Uploading hbase-site.xml

You can place hbase-site.xml in the project's resources folder and add it to the class_path. By doing this, you can remove the line config.set("hbase.zookeeper.quorum", "ubuntu01,ubuntu02,ubuntu03");. This is because it uses the quorum information from inside hbase-site.xml. This approach is also more recommended.