thrift api java客户端与hbase连接

3phpmpom  于 2021-06-09  发布在  Hbase
关注(0)|答案(1)|浏览(537)

软件包使用:

import org.apache.hadoop.hbase.thrift.generated.AlreadyExists;
import org.apache.hadoop.hbase.thrift.generated.ColumnDescriptor;
import org.apache.hadoop.hbase.thrift.generated.Hbase;
import org.apache.hadoop.hbase.thrift.generated.IOError;
import org.apache.hadoop.hbase.thrift.generated.IllegalArgument;
import org.apache.hadoop.hbase.thrift.generated.Mutation;
import org.apache.hadoop.hbase.thrift.generated.TCell;
import org.apache.hadoop.hbase.thrift.generated.TRowResult;

import org.apache.thrift.TException;
import org.apache.thrift.protocol.TBinaryProtocol;
import org.apache.thrift.protocol.TProtocol;
import org.apache.thrift.transport.TSocket;
import org.apache.thrift.transport.TTransport;
import org.apache.thrift.transport.TTransportException;

调用方法

public void start() {
            try {
                TTransport socket = new TSocket("host-name", 9090);// IP Host Name
                TProtocol protocol = new TBinaryProtocol(socket, true, true);// Note here
                Hbase.Client client = new Hbase.Client(protocol);
                socket.open();
                System.out.println("open");
                try {
                    System.out.println("scanning tables...");
                    for (byte[] name : client.getTableNames()) { 
                        //code
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                    out.println(e.getMessage());
                }
                socket.close();
                out.println("close");
            } catch (TTransportException e) {
                e.printStackTrace();
                out.println(e.getMessage());
            } catch (TException e) {
                e.printStackTrace();
                out.println(e.getMessage());

            }
}

问题:
代码java get error:方法名无效:“gettablenames”我无法在hbase中提供列表可能是缺少的包有问题

谢谢你的帮助

lkaoscv7

lkaoscv71#

谢谢,问题解决了,我在hbase-0.94.19.tar.gz\hbase-0.94.19\src\examples\thrift2中使用了democlient.java,这个rar比我在服务器上安装的要多。我添加了这个依赖项

<dependency>
        <groupId>org.apache.hbase</groupId>
        <artifactId>hbase-thrift</artifactId>
        <version>0.98.2-hadoop2</version>
        <type>jar</type>
    </dependency>

相关问题