Explanation
In the previous article dotnetcore with one hbase --hbase environment ready after the end, we have hbase database environment. Then you can take advantage of thrift generate c # hbase the client. If you do not understand thrift, please poke here .
dotnet core realization of thrift
thrift added from version 0.11.0 of netcore have achieved. There are versions of .net farmwork realize this before. In order to use with dotnet core version we chose the oldest version 0.11.0 installed. But that there is a problem, hbase in the thrift version is 0.9.0, the version inconsistencies cause some transport protocol can not be used, the current test only a simple binary protocol TBinaryProtocol
can! ! !
1. thrift installation
thrift-0.11.0 from here download.
ubuntu18.04 installation thrift go here or on their own Baidu.
2. thrift hbase generation
Find hbase1.2.8 extract the folder Hbase.thrift
, you can use the Linux command find ./ -name Hbase.thrift
to find out.
hbase-1.2.8|⇒ find ./ -name Hbase.thrift
./hbase-thrift/src/main/resources/org/apache/hadoop/hbase/thrift/Hbase.thrift
Open into the containing Hbase.thrift
directory, execute the command generation thrift --gen netcore Hbase.thrift
. Generally have the following warning can be ignored:
[WARNING:/home/hsx/Downloads/hbase-1.2.8-src/hbase-1.2.8/hbase-thrift/src/main/resources/org/apache/hadoop/hbase/thrift/Hbase.thrift:89] The "byte" type is a compatibility alias for "i8". Use "i8" to emphasize the signedness of this type.
View command execution ls -al
, see the generated foldergen-netcore
total 40
drwxr-xr-x gen-netcore
-rw-rw-r-- Hbase.thrift
Into the gen-netcore
folder may see some c # code:
total 716K
-rw-r--r-- AlreadyExists.cs
-rw-r--r-- BatchMutation.cs
-rw-r--r-- ColumnDescriptor.cs
-rw-r--r-- Hbase.cs
-rw-r--r-- IllegalArgument.cs
-rw-r--r-- IOError.cs
-rw-r--r-- Mutation.cs
-rw-r--r-- TAppend.cs
-rw-r--r-- TCell.cs
-rw-r--r-- TColumn.cs
-rw-r--r-- TIncrement.cs
-rw-r--r-- TRegionInfo.cs
-rw-r--r-- TRowResult.cs
-rw-r--r-- TScan.cs
We simply create a new Class Library project dotnet, for example dotnet new classlib -o HbaseNetCore
, directly to copy these files to the library project directory on the line. Open the project and found it quoted thrift, but unable to find references are given:
using Thrift;
using Thrift.Collections;
using Thrift.Protocols;
using Thrift.Protocols.Entities;
using Thrift.Protocols.Utilities;
using Thrift.Transports;
using Thrift.Transports.Client;
using Thrift.Transports.Server;
Next introduce acquiring thrift project to solve the problems cited.
3. Get thrift project
Open thrift-0.11.0 decompression folders, perform a search find ./ -name netcore
, as follows:
./lib/netcore # c#实现的thrift源码
./tutorial/netcore # c#实现的thrift使用教程
./test/netcore # 测试
What we really need is ./lib/netcore
in the thrift
project. In fact, ./lib/
there are thrift languages to achieve, such as:
lib|⇒ ls
as3 csharp erl java lua netcore php st
c_glib d go javame Makefile nodejs py ts
cocoa dart haxe js Makefile.am ocaml rb xml
cpp delphi hs json Makefile.in perl rs
Find ./lib/netcore/thrift
, copy the project to the second step of the project HbaseNetCore
next, and then HbaseNetCore
reference thrift
the project can be. In fact, before creating all projects should create a solution to manage projects, create their own readers.
4. Test
New Test project to test more than the generated client. See the specific implementation here HBase C # and the .NET Thrift in the Tutorial .
to sum up
The above steps are basic online tutorials listed here to make the original author is confusing places, such as readers for help, it could not be better. As has been kept informed reader, skip own.
Hbase due to inconsistencies thrift and used in the version, can only lead to the use of a simple binary protocol TBinaryProtocol
! ! !
The latter will do some of the HbaseNetCore
projects help tool. Stay tuned.