当前位置:网站首页>thrift简单使用
thrift简单使用
2022-06-30 09:32:00 【Zip-List】
git clone https://github.com/apache/thrift.git
//官网readme.md
安装
安装bison flex包
https://blog.csdn.net/Tosonw/article/details/102640385
openssl/opensslv.h: No such file or directory
sudo apt-get install libssl-dev
thriftl.cc找不到
thrift updating lex.yythrift/thriftl.cc mv: cannot move ‘tmp-thriftl.cc’ to ‘…/lex.yythrift/thriftl.cc’: No such file or directory
https://github.com/sunchao/parquet-rs/issues/74
重新./boosttrap.sh + ./configure
make
make install
thrift --version
简单使用
https://diwakergupta.github.io/thrift-missing-guide/
https://blog.csdn.net/tuwenqi2013/article/details/105541475
---gen-cpp
---Serv_server.skeleton.cpp
---Serv.cpp
---Serv.h
---student_types.cpp
---student_types.h
cleint.cpp
server.cpp
student.thrift
1 定义thrift文件
student.thrift
使用, 且没有;
struct Student{
1: i32 sno,
2: string sname,
3: bool ssex,
4: i16 sage,
}
service Serv{
void put(1: Student s),
}
thrift -r --gen cpp student.thrift 生成gen-cpp文件夹
- 没有教程中的xxx_constant.cpp文件是因为thrift定义中没有const常量,不影响
- 生成文件Serv_server.skeleton.cpp中类似svr部分代码,不用处理,不会在生成的文件夹中写逻辑
2 server.cpp/client.cpp
server 实现put函数的handler
// This autogenerated skeleton file illustrates how to build a server.
// You should copy it to another filename to avoid overwriting it.
#include "gen-cpp/Serv.h""
#include <thrift/protocol/TBinaryProtocol.h>
#include <thrift/server/TSimpleServer.h>
#include <thrift/transport/TServerSocket.h>
#include <thrift/transport/TBufferTransports.h>
using namespace ::apache::thrift;
using namespace ::apache::thrift::protocol;
using namespace ::apache::thrift::transport;
using namespace ::apache::thrift::server;
class ServHandler : virtual public ServIf {
public:
ServHandler() {
// Your initialization goes here
}
void put(const Student& s) {
// Your implementation goes here
printf("put\n");
printf("name:%s\n", s.sname.c_str());
printf("sex:%d\n", s.ssex);
}
};
int main(int argc, char **argv) {
int port = 9090;
::std::shared_ptr<ServHandler> handler(new ServHandler());
::std::shared_ptr<TProcessor> processor(new ServProcessor(handler));
::std::shared_ptr<TServerTransport> serverTransport(new TServerSocket(port));
::std::shared_ptr<TTransportFactory> transportFactory(new TBufferedTransportFactory());
::std::shared_ptr<TProtocolFactory> protocolFactory(new TBinaryProtocolFactory());
TSimpleServer server(processor, serverTransport, transportFactory, protocolFactory);
server.serve();
return 0;
}
client 与对应的handler服务器建立连接,进行远程调用
#include "gen-cpp/Serv.h"
#include </usr/local/include/thrift/transport/TSocket.h>
#include </usr/local/include/thrift/transport/TBufferTransports.h>
#include </usr/local/include/thrift/protocol/TBinaryProtocol.h>
#include <iostream>
using namespace apache::thrift;
using namespace apache::thrift::protocol;
using namespace apache::thrift::transport;
//using boost::shared_ptr;
int main(int argc, char **argv) {
std::shared_ptr<TSocket> socket(new TSocket("127.0.0.1", 9090));
std::shared_ptr<TTransport> transport(new TBufferedTransport(socket));
std::shared_ptr<TProtocol> protocol(new TBinaryProtocol(transport));
transport->open();
//*****************添加部分******************
Student s;
s.sno = 123;
s.sname = "xiaoshe";
s.ssex = 1;
s.sage = 30;
ServClient client(protocol);
std::cout<<"client send a data"<<std::endl;;
client.put(s);
//*****************添加部分******************
transport->close();
return 0;
}
3 编译
g++ -g -o server -Ithrift ./gen-cpp/Serv.cpp ./gen-cpp/student_types.cpp server.cpp -lthrift
g++ -g -o client -Ithrift ./gen-cpp/Serv.cpp ./gen-cpp/student_types.cpp client.cpp -lthrift
cannot find libthrift.so
ldd ./server
sudo find / -name libthrift-0.17.0.so 看看是不是有这个文件
1、在usr/lib目录下有这些库文件
直接修复以下链接即可,例如依次执行
ln -s lib***.so.6(某个数字) lib***.so
2、在usr/lib目录下没有这些文件
直接在系统根目录中依次搜索这些库文件,并使用
sudo cp 库文件名 /usr/lib
命令将相应库文件拷贝到该目录中即可
边栏推荐
- ES6 learning path (II) let & const
- Installation, use and explanation of vulnerability scanning tool OpenVAS
- 八大排序(一)
- Pytorch for former Torch users - Tensors
- Dart asynchronous task
- Six implementation methods of singleton mode
- Cb/s Architecture - Implementation Based on cef3+mfc
- Properties of string
- 桂林 穩健醫療收購桂林乳膠100%股權 填補乳膠產品線空白
- Tclistener server and tcpclient client use -- socket listening server and socketclient use
猜你喜欢

Tutorial for beginners of small programs day01

Numpy (time date and time increment)

MySQL优化

Self service terminal handwritten Chinese character recognition input method library tjfink introduction

Express file download

桂林 稳健医疗收购桂林乳胶100%股权 填补乳胶产品线空白

Using appbarlayout to realize secondary ceiling function

5. Messager framework and imessager interface

Guilin robust medical acquired 100% equity of Guilin Latex to fill the blank of latex product line

So the toolbar can still be used like this? The toolbar uses the most complete parsing. Netizen: finally, you don't have to always customize the title bar!
随机推荐
2021-10-20
UltraEdit delete empty line method
Create thread pool demo
ES6 learning path (II) let & const
Bluetooth BT RF test (forwarding)
Talk about how the kotlin collaboration process establishes structured concurrency
Abstract factory pattern
Esp32 (7): I2S and I2C drivers for function development
JPA naming rules
Do you want the dialog box that pops up from the click?
Splice and slice functions of JS
ES6 learning road 5 symbol
Installation, use and explanation of vulnerability scanning tool OpenVAS
Clickhouse installation (quick start)
Deep understanding of kotlin collaboration context coroutinecontext
Explanation on the use of password profiteering cracking tool Hydra
Research on lg1403 divisor
2020-11-02
仿照微信Oauth2.0接入方案
Idea shortcut key settings