日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 人文社科 > 生活经验 >内容正文

生活经验

windows下rpc框架thrift的环境配置

發布時間:2023/11/27 生活经验 41 豆豆
生活随笔 收集整理的這篇文章主要介紹了 windows下rpc框架thrift的环境配置 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

windows下rpc框架thrift的環境配置

引用鏈接:
https://www.cnblogs.com/49er/p/7193829.html

最近在弄windows下 的Facebook的rpc 框架 thrift ,
網上東西看了很多, 但是大都不能一篇到位, 這里總結了一下,
也記一下自己遇到的問題和解決的方法

這里把我在實際過程中遇見的問題,以及問題的解決方法寫一下:

1、版本問題:

基本是參照現這個版本來的:

  • Windows 10
  • Microsoft Visual Studio 2017
  • Apache Thrift 0.9.2.
  • Boost 1.72.0.
  • libevent-2.1.11-stable
  • OpenSSL 1.0.2l

2、概述

總體有兩種思路,一種是利用virtual studio 的nuget 包管理工具,編譯安裝thrift以及其libevent,boost,openssl這幾個依賴庫,

一種是從這些各自的官網,或者git-hub上下載源碼編譯安裝,但是由于我本地的nuget一直無法連接(有vpn),遂放棄這種方式

這個方式的指導連接在這里:

https://blog.csdn.net/xie1xiao1jun/article/details/53332504

3、實際問題

1、openssl, 原文的openssl編譯安裝方式寫的部分地方不正確 以下是糾正部分:

https://blog.csdn.net/fm0517/article/details/91578554

4. 打開VS命令行工具

VS2013 x64 本機工具命令提示,進入目錄下面的目錄中
D:\ProgramIDE\Microsoft Visual Studio 12.0\VC\bin\amd64
執行命令:vcvars64.bat

5. 進入openssl源碼目錄下,執行配置

perl Configure VC-WIN64A no-asm --prefix=D:\360Downloads\openssl-1.0.2s
其中prefix后面的路徑是源碼路徑。

2、libevet 配置文件找不到

使用libevent的問題
1)找不到<event2/event-config.h>
event-config.h在E:\libevent-2.1.8-stable\WIN32-Code\nmake\event2目錄下,

因此編譯完成后要把E:\libevent-2.1.8-stable\WIN32-Code\nmake下的所有文件和目錄拷貝到E:\libevent-2.1.8-stable\include

以下是原文

Windows 10 Visual Studio 2017 安裝配置 Apache Thrift (C++)
最近需要使用Thrift,所以在網上看了很多資料,不過很多教程都不夠詳細完整,導致我花了不少時間安裝配置。在這里我把我配置的過程寫下來和大家分享。

1 介紹
Apache Thrift 是一個跨語言的遠程過程調用框架(RPC,Remote Procedure Call)。首先使用接口描述語言(IDL,Interface Description Language)編寫 .thrift 文件,然后通過 Thrift 編譯成C++、JAVA、C# 等語言的代碼。這些代碼之間可以互相遠程調用。Thrift 封裝了底層網絡通信的內容,用戶只需要編寫頂層邏輯代碼就可以了。

2 測試環境
Windows 10
Microsoft Visual Studio 2017
Apache Thrift 0.9.2.
Boost 1.64.0.
libevent-2.1.8-stable
OpenSSL 1.0.2l
3 使用 Visual Sdutio 2017 編譯生成 libthrift.lib
下載安裝Boost,記住**{Boost安裝目錄}。安裝過程見Windows 10 Visual Studio 2017 安裝配置 Boost。
下載安裝OpenSSL,下載網址。安裝過程見Windows 10 Visual Studio 2017 安裝配置 OpenSSL。記住
{OpenSSL 目錄}**
從 Apache Thrift 官網下載 Windows 平臺的 Thrift 源代碼和編譯器。
下載libevent,非阻塞的 Thrift 服務器需要這個庫。
解壓縮下載的文件。
去**{thrift 安裝目錄}\lib\cpp 目錄,點擊thrift.sln**,打開 VS 項目,里面有兩個項目libthrift 和 libthriftnb。
會有一個對話框詢問是否升級,點擊升級。
打開 Developer Command Prompt for VS 2017。

在 Developer Command Prompt 中進入 {libevent 安裝目錄}。
輸入 nmake -f Makefile.nmake 來安裝libevent。
完后后,右鍵 libthrift項目,點擊屬性 > C/C++ > 常規。
在附加包含目錄中添加:
{boost 安裝目錄}\boost_1_64_0;{boost 安裝目錄}\boost_1_64_0\boost;{OpenSSL 目錄}\inc32
點擊庫管理器 > 附加庫目錄,添加如下文件:
{OpenSSL 目錄}\out32dll
右鍵 libthriftnb項目,點擊屬性 > C/C++ > 常規。在附加包含目錄中添加
{boost 安裝目錄}\boost_1_64_0;{boost 安裝目錄}\boost_1_64_0\boost;{OpenSSL 目錄}\inc32;{libevent_install_dir};{libevent_install_dir}\include;{libevent_install_dir}\WIN32-Code;
點擊庫管理器 > 附加庫目錄,添加如下文件:
{OpenSSL 目錄}\out32dll
然后編譯生成文件,如果使用DEBUG模式,會在**{thrift 目錄}\lib\cpp\DEBUG**中生成libthrift.lib。
4 建立 Server、Client 示例
4.1 建立 Thrift C++ Server
創建Hello.thrift文件

Hello.thrift

namespace cpp Demo 
service Hello{ string helloString(1:string para) i32 helloInt(1:i32 para) bool helloBoolean(1:bool para) void helloVoid() string helloNull() } 

編譯生成 C++ 源文件,會生成 gen-cpp文件夾

thrift -r --gen cpp Hello.thrift

生成的文件如下:

新建 Visual Studio 項目,并將生成的文件粘貼入項目文件夾中。

我們只需要實現Hello_server.skeleton.cpp中的方法即可。

右鍵項目,點擊屬性 > C/C++ > 常規 > 附加包含目錄,添加:
{thrift 安裝目錄}\lib\cpp\src;{thrift 安裝目錄}\lib\cpp\src\thrift\windows;{boost 安裝目錄}\boost\boost_1_64_0;%(AdditionalIncludeDirectories)

點擊鏈接器 > 常規 > 附加庫目錄,添加:

{boost 安裝目錄}\boost\boost_1_64_0\stage\lib;{thrift 安裝目錄}\lib\cpp\Debug;%(AdditionalLibraryDirectories)

點擊鏈接器 > 所有選項 > 附加依賴項,添加:

libboost_thread-vc141-mt-gd-1_64.lib;libboost_chrono-vc141-mt-gd-1_64.lib;libthrift.lib;

如果是 0.91 之前的 thrift,還需要在Hello_server.skeleton.cpp源文件main函數前面加上如下代碼:

WSADATA wsaData = {};
WORD wVersionRequested = MAKEWORD(2, 2);
int err = WSAStartup(wVersionRequested, &wsaData);

點擊生成,Server端就可以啟動了。
這些庫的名稱要以你自己安裝的庫為準,你需要去boost文件夾中查看這些庫的準確名稱。上面 {} 里面的安裝目錄也是這樣。

4.2 生成 Thrift C++ Client
和 Server 的配置過程一樣,只不過我們不用Hello_server.skeleton.cpp。我們需要自己編寫客戶端:

#include "Hello.h"
#include <thrift/transport/TSocket.h> 
#include <thrift/transport/TBufferTransports.h> 
#include <thrift/protocol/TBinaryProtocol.h> 
#include <iostream>
#include <string>using namespace apache::thrift;
using namespace apache::thrift::protocol;
using namespace apache::thrift::transport;
using boost::shared_ptr;int main(int argc, char **argv) {boost::shared_ptr<TSocket> socket(new TSocket("localhost", 9090));boost::shared_ptr<TTransport> transport(new TBufferedTransport(socket));boost::shared_ptr<TProtocol> protocol(new TBinaryProtocol(transport));// 只需要實例化 HelloClient,然后就可以遠程過程調用了Demo::HelloClient client(protocol);   transport->open();// Your Codes std::cout << client.helloInt(10030341) << std::endl;std::string tem = "hello from Client";client.helloString(tem, tem);std::cout << tem << std::endl;transport->close();return 0;
}

4.3 演示
4.3.1 Server

4.3.2 Client

二、nuget方式
配置nuget boost 庫
點擊右鍵:管理nuget程序包

Install-Package boost-vc140

(v1.62.0)

Install-Package openssl.v140.windesktop.msvcstl.dyn.rt-dyn

(OpenSSL 1.0.2d )

Install-Package libevent_vc120

(2.14 )

編譯完成:

拷貝src,lib文件到項目

給出一個windows配置好的版本

里面包括vs2013,vs2015

thrift-master-0.9.3\lib\cppVS2013

thrift-master-0.9.3\lib\cppVS2015
————————————————
版權聲明:本文為CSDN博主「冰_封」的原創文章,遵循 CC 4.0 BY-SA 版權協議,轉載請附上原文出處鏈接及本聲明。
原文鏈接:https://blog.csdn.net/xie1xiao1jun/article/details/53332504

總結

以上是生活随笔為你收集整理的windows下rpc框架thrift的环境配置的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。