C#版Nebula客戶端編譯

靜若清池發表於2021-07-19

一、需求背景

從Nebula的Github上可以發現,Nebula為以下語言提供了客戶端SDK:

nebula-cpp
nebula-java
nebula-go
nebula-python
nebula-node
nebula-rust

我們公司的業務開發語言是C#,但Nebula卻沒有提供C#版的客戶端。

由於Nebula支援原始碼編譯,索性只好嘗試動手編譯一個。

 

二、Thrift簡介

1.Thrift是Facebook在2007年貢獻給Apache基金會的一個開源專案:https://thrift.apache.org/

Thrift可以支援多種程式語言,例如:  C++, C#, Cocoa, Erlang, Haskell, Java, Ocami, Perl, PHP, Python, Ruby, Smalltalk。

Thrift可以作為二進位制的高效能的通訊中介軟體,支援資料(物件)序列化和多種型別的RPC服務

2.Facebook自己也維護了一個Thrift,目前已經和Apache的Thrift差別較大,重寫了編譯器,重新實現了一個全非同步的Thrift Server:https://github.com/facebook/fbthrift

Facebook Thrift is not a distribution of Apache Thrift. 
This is an evolved internal branch of Thrift that Facebook re-released to open source community in February 2014.
Facebook Thrift was originally released closely tracking Apache Thrift but is now evolving in new directions.
In particular, the compiler was rewritten from scratch and the new implementation features a fully asynchronous Thrift server.

3.Nebula的客戶端基於Thrift檔案進行編譯的,但是Thrift不是Apache的Thrift,而是Facebook的Thrift,有點繞

 

三、編譯前準備工作

1.作業系統

  通過VMware搭建的本地CenOS 7,虛擬機器與主機健通過NAT網路連線,記憶體8G,宿主機有梯子可以FQ

 

 

2.安裝依賴

root# yum update
root# yum install -y make \
                 m4 \
                 git \
                 wget \
                 unzip \
                 xz \
                 readline-devel \
                 ncurses-devel \
                 zlib-devel \
                 gcc \
                 gcc-c++ \
                 cmake \
                 gettext \
                 curl \
                 redhat-lsb-core \
                 bzip2

 

3.檢查主機上的GCC和CMake版本是否正確

root# g++ --version
root# cmake --version

發現版本不正確,並且git clone也不好使,只好手動下載2.0.1版本的nebula-common:https://github.com/vesoft-inc/nebula-common/tree/v2.0.1

 

 

4.解壓上述的nebula-common-2.0.1.zip解壓,進入nebula-common-2.0.1根目錄

 

5.依次執行如下命令

// 安裝CMake。
root# ./third-party/install-cmake.sh cmake-install

// 啟用CMake。
root# source cmake-install/bin/enable-cmake.sh

//opt目錄新增寫許可權。
root# sudo mkdir /opt/vesoft && sudo chmod -R a+w /opt/vesoft

// 安裝GCC。安裝到opt目錄需要寫許可權,使用者也可以修改為其他目錄。
root# ./third-party/install-gcc.sh --prefix=/opt

// 啟用GCC。
root# source /opt/vesoft/toolset/gcc/7.5.0/enable

// 安裝第三方依賴
root# ./third-party/install-third-party.sh

 

四、編譯

1.進入上述的nebula-common-2.0.1根目錄

2.依次執行命令

root#cmake
root#make

3.檢視基於Thrift模板生成的C#程式碼

nebula-common-2.0.1/src/common/interface/gen-csharp/nebula

 

 

五、後續工作

參考Nebula提供的Java的客戶端程式碼,翻譯成對應的C#程式碼

 

六、參考文件

https://docs.nebula-graph.com.cn/2.0.1/4.deployment-and-installation/1.resource-preparations/

相關文章