Skip to content

Split View: HBase Client API 기초

|

HBase Client API 기초

Overview

HBase를 다루는데 사용하는 HBase Client API의 종류를 알아봅니다.

HBase Client Download

hbase-maven-link

이 링크에 접속하면 HBase Client Maven Download Link HBase Client 파일을 pom.xml 에 추가하기 위한 Maven repository를 알 수 있습니다.

접속 준비

pom.xml

만약 maven으로 프로젝트를 구성했다면, pom.xml에 아래와 같이 dependency를 추가할 수 있습니다. HBase Client 2.5.2 version을 선택했습니다.

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>

hbase-site.xml 준비

HBase 를 사용하려면, 프로세스가 HBase에 대한 서버 정보를 알아야합니다. HBase 는 Zookeeper로 클러스터에 대한 meta 정보가 관리되기 때문에, Zookeeper quorum 정보마 있으면 됩니다. 이 때 아래 2가지 방법이 있고, 두 방법 모두 알아보겠습니다.

  1. Zookeeper Quorum 정보가 들어간, configuration을 동적으로 생성하기.
  2. hbase-site.xml을 class-path에 추가하기.

zookeeper quorum 정보 수동 입력

        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());

hbase-site.xml 업로드.

hbase-site.xml 을 프로젝트의 resources 폴더에 넣고, class_path로 추가하는 법이 있다. 이렇게 하게되면, config.set("hbase.zookeeper.quorum", "ubuntu01,ubuntu02,ubuntu03"); 이 line을 삭제해도 된다. hbase-site.xml 내부의 쿼럼 정보를 사용하기 때문이다. 그리고 이 방식이 더 권장된다.

HBase Client API Basics

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.

Quiz

Q1: What is the main topic covered in "HBase Client API Basics"? Learn the basics of the HBase Client API used to interact with HBase.

Q2: What is 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.

Q3: Explain the core concept of 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.