LOCKLOSE 发表于 2018-11-22 10:05:05

Apache Thrift

  Windows7上运行的C#客户端需要与在Ubuntu Server上使用nodejs构建的服务器进行跨平台跨语言的通信,选择使用开源软件thrift解决此问题。
  Thrift相关介绍:
Apache Thrift入门1-架构&介绍
  Thrift Wiki
  一.Ubuntu上安装Apache Thrift
  安装requirements:http://thrift.apache.org/docs/install/debian
$sudo apt-get install libboost-dev libboost-test-dev libboost-program-options-dev libboost-system-dev libboost-filesystem-dev libevent-dev automake libtool flex bison pkg-config g++ libssl-dev
$javac
$sudo apt-get install
$sudo apt-get install antOptional packages--Csharp
$sudo apt-get install mono-gmcs mono-devel libmono-system-web2.0-cil nunit nunit-console  Download Apache Thrift:https://thrift.apache.org/download
$wget http://mirrors.sonic.net/apache/thrift/0.9.1/thrift-0.9.1.tar.gz  or
$git clone https://git-wip-us.apache.org/repos/asf/thrift.git thrift
$cd thrift  从源码编译:https://thrift.apache.org/docs/BuildingFromSource   http://www.geilthings.com/wiki/Thrift
  error&solution:有些语言环境支持出现问题,配置时加上 --without=XXX 选项,不包含不必要的语言支持。
  https://issues.apache.org/jira/browse/THRIFT-2265
  http://wbj0110.iteye.com/blog/1988455
  error&solution:thrift thrift 安装 make 失败 ar: .libs/ThriftTest_constants.o: No such file or directory
  http://stackoverflow.com/questions/18643642/libtool-error-building-thrift-0-9-1-on-ubuntu-13-04
  http://www.cnblogs.com/q191201771/p/3878682.html


[*]  cd ./thrift-0.9.0/tutorial
[*]  thrift -r -gen cpp tutorial.thrift// -r对其中include的文件也生成服务代码 -gen是生成服务代码的语言
[*]  cd cpp
[*]  make
  运行TutorialServer 和 TutorialClient

  Writing a .thrift file,
   generate the source from a thrift file run
thrift --gen  利用apache Thrift 进行 node.js和 C++进程间通讯时遇到如下问题:
  在运行client和server时出现错误:
libthrift-0.9.1.so: cannot open shared object file: No such file or directory

  How to set the environmental variable LD_LIBRARY_PATH in linux
$vim ~/.bashrc
export LD_LIBRARY_PATH=/usr/local/lib
$source ~/.bashrc  二.windows下安装与实现thrift
  1.下载thrift:thrift-0.9.1.exe   thrift-0.9.1.tar.gz

  thrift-0.9.1.tar.gz
  Thrift compiler for Windows (thrift-0.9.1.exe)
  2.下载安装boost:(c++需要该标准库,c#略过这一步)
  http://www.boost.org/
  参考链接:
  http://www.cnblogs.com/ComputerG/archive/2011/03/10/1979730.html
  http://download.csdn.net/detail/snrmp0711/5896485
  

  编译boost:
  3.编译thrift脚本,生成类文件,cmd:
  thrift-0.9.1.exe -r --gen csharp tutorial.thrift

  产生gen-csharp文件夹,有如下文件:

  4.支持C#的Thrift.dll
  在thrift-0.9.1/lib/csharp/ 下存在Thrift.dll文件
  或者使用thrift-0.9.1/lib/csharp/src/文件夹下的代码通过VS2012编译

  编译Thrift Solution,产生Thrift.dll文件:

  4.添加thrift生成的文件以及Client Server文件,并且添加工程引用Thrift.dll

  运行分别debug/下的Server.exe与Client.exe,结果如下:

  修改Client代码的IP,为nodjs-server所在IP,重新生成方案,分别运行node nodeserver.js与Client.exe,成功进行远程调用。则Windows7上的C#与Ubuntu Server 14.04上的Nodejs通过thrift进行跨平台跨语言的通信。
  参考链接:
  Thrift初探:简单实现C#通讯服务程序
  三.使用用同一个.thrift文件生成的struct和service编写服务器程序和客户端,则可以实现跨平台跨语言的通信

  




页: [1]
查看完整版本: Apache Thrift