zoukankan      html  css  js  c++  java
  • hbase学习笔记-----REST客户端

    1. 启动REST服务 

      a.启动一个非守护进程模式的REST服务器(ctrl+c 终止)

         bin/hbase rest start 

      b.启动守护进程模式的REST服务器

         bin/hbase-daemon.sh start rest

      默认启动的是8080端口(可以使用参数在启动时指定端口),可以被访问。eg.  curl  http://<servername>:8080/

    2.访问服务端的数据

    3.使用Java API访问  

     1 package rest;
     2 
     3 import org.apache.hadoop.conf.Configuration;
     4 import org.apache.hadoop.hbase.HBaseConfiguration;
     5 import org.apache.hadoop.hbase.client.Get;
     6 import org.apache.hadoop.hbase.client.Result;
     7 import org.apache.hadoop.hbase.client.ResultScanner;
     8 import org.apache.hadoop.hbase.client.Scan;
     9 import org.apache.hadoop.hbase.rest.client.Client;
    10 import org.apache.hadoop.hbase.rest.client.Cluster;
    11 import org.apache.hadoop.hbase.rest.client.RemoteHTable;
    12 import org.apache.hadoop.hbase.util.Bytes;
    13 import util.HBaseHelper;
    14 
    15 import java.io.IOException;
    16 
    17 /**
    18  * Created by root on 15-1-9.
    19  */
    20 public class RestExample {
    21     public static void main(String[] args) throws IOException {
    22         Configuration conf = HBaseConfiguration.create();
    23 
    24         HBaseHelper helper = HBaseHelper.getHelper(conf);
    25         helper.dropTable("testtable");
    26         helper.createTable("testtable", "colfam1");
    27         System.out.println("Adding rows to table...");
    28         helper.fillTable("testtable", 1, 10, 5, "colfam1");
    29 
    30         Cluster cluster=new Cluster();
    31         cluster.add("hadoop",8080);
    32 
    33         Client client=new Client(cluster);
    34 
    35         RemoteHTable table=new RemoteHTable(client,"testtable");
    36 
    37         Get get = new Get(Bytes.toBytes("row-30")); 
    38         get.addColumn(Bytes.toBytes("colfam1"), Bytes.toBytes("col-3"));
    39         Result result1 = table.get(get);
    40 
    41         System.out.println("Get result1: " + result1);
    42 
    43         Scan scan = new Scan();
    44         scan.setStartRow(Bytes.toBytes("row-10"));
    45         scan.setStopRow(Bytes.toBytes("row-15"));
    46         scan.addColumn(Bytes.toBytes("colfam1"), Bytes.toBytes("col-5"));
    47         ResultScanner scanner = table.getScanner(scan); 
    48         for (Result result2 : scanner) {
    49             System.out.println("Scan row[" + Bytes.toString(result2.getRow()) +
    50                     "]: " + result2);
    51         }
    52 
    53     }
    54 
    55 }
    View Code
  • 相关阅读:
    聊一聊c++中指针为空的三种写法 ----->NULL, 0, nullptr
    HTML的教程网址
    c++构造函数谁先执行的问题
    从一个模板函数聊聊模板函数里面如何获得T的名字
    sourceInsight的技巧
    【java】实体类中 Set<对象> 按照对象的某个字段对set排序
    hibernate实体xml一对多关系映射
    layer父页面调用子页面的方法
    FreeMarker的<#if></#if>标签
    怎么把myeclipse项目导入IDEA中
  • 原文地址:https://www.cnblogs.com/goodlucklzq/p/4207103.html
Copyright © 2011-2022 走看看