当前位置: 首页 > news >正文

ubuntu下Thrift安装

thrift是一种常用rpc框架,工作中经常会用到,本文记录一下其安装过程。

目录

1.下载软件包

1.1thrift下载

1.2libevent下载

1.3boost下载

 2.安装(注意步骤)

2.1安装libevent

2.2安装boost 

2.3安装与Python2.7版本对应的python-dev

2.4安装Thrift

 3.测试安装


1.下载软件包

1.1thrift下载

Apache Thrift - Downloadhttps://thrift.apache.org/download

1.2libevent下载

https://libevent.org/https://libevent.org/

1.3boost下载

Boost C++ Librarieshttp://www.boost.org/%C2%A0

 2.安装(注意步骤)

2.1安装libevent

tar -zxvf libevent-2.1.12-stable.tar.gz 
cd libevent-2.1.12-stable/
sudo ./configure --prefix=/usr/local/libevent
sudo make
sudo make install

2.2安装boost 

tar -zxvf boost_1_81_0_rc1.tar.gz 
cd boost_1_81_0/
sudo ./bootstrap.sh --prefix=/usr/local/boost
sudo ./b2
sudo ./b2 install

2.3安装与Python2.7版本对应的python-dev

sudo apt-get install python2.7-dev

2.4安装Thrift

https://dlcdn.apache.org/thrift/0.18.1/thrift-0.18.1.tar.gz
tar -zxvf thrift-0.18.1.tar.gz
cd thrift-0.18.1
chmod +x configure
sudo ./configure --with-boost=/usr/local/boost --prefix=/usr/local/thrift
sudo make
sudo make install

查看thrift版本:

/usr/local/thrift/bin/thrift -version

 3.测试安装

以官网协议StressTest.thrift为例:

/** Licensed to the Apache Software Foundation (ASF) under one* or more contributor license agreements. See the NOTICE file* distributed with this work for additional information* regarding copyright ownership. The ASF licenses this file* to you under the Apache License, Version 2.0 (the* "License"); you may not use this file except in compliance* with the License. You may obtain a copy of the License at**   http://www.apache.org/licenses/LICENSE-2.0** Unless required by applicable law or agreed to in writing,* software distributed under the License is distributed on an* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY* KIND, either express or implied. See the License for the* specific language governing permissions and limitations* under the License.*/namespace cpp test.stress
namespace d thrift.test.stress
namespace go stressservice Service {void echoVoid(),i8 echoByte(1: i8 arg),i32 echoI32(1: i32 arg),i64 echoI64(1: i64 arg),string echoString(1: string arg),list<i8>  echoList(1: list<i8> arg),set<i8>  echoSet(1: set<i8> arg),map<i8, i8>  echoMap(1: map<i8, i8> arg),
}

//同步代码生成
/usr/local/thrift/bin/thrift -r --gen cpp StressTest.thrift 

//异步代码生成
/usr/local/thrift/bin/thrift --gen cpp:cob_style StressTest.thrift 

备注: 

//生成java代码

thrift -r --gen java student.thrift  

//生成python代码
thrift -r --gen py student.thrift    

client.cpp

#include <iostream>
#include <string>
#include <thrift/transport/TTransportUtils.h>
#include <thrift/transport/TSocket.h>
#include <thrift/protocol/TBinaryProtocol.h>
#include "Service.h"using namespace  ::test::stress;
using namespace apache::thrift;
using namespace apache::thrift::protocol;
using namespace apache::thrift::transport;int main()
{std::shared_ptr<TSocket> socket(new TSocket("localhost", 9090));std::shared_ptr<TTransport> transport(new TFramedTransport(socket));std::shared_ptr<TProtocol> protocol(new TBinaryProtocol(transport));ServiceClient client(protocol);transport->open();std::cout << "client echoByte byte=" << client.echoByte('A') << std::endl;std::cout << "send_echoByte('B')" << std::endl;client.send_echoByte('B');std::cout << "send_echoByte('C')" << std::endl;client.send_echoByte('C');std::cout << "recv_echoByte()" << client.recv_echoByte() << std::endl;std::cout << "recv_echoByte()" << client.recv_echoByte() << std::endl;transport->close();return 0;
}

客户端编译:

g++ -std=c++11 -I./gen-cpp -I/usr/local/thrift/include  -I/usr/local/libevent/include -I/usr/local/libevent/include/event2 -I/usr/local/boost/include  gen-cpp/Service.cpp  client.cpp -o client -L /usr/local/thrift/lib  -lthrift  -L /usr/local/libevent/lib -levent -L /usr/local/boost/lib -lboost_json

代码目录结构如下:

http://www.lryc.cn/news/58779.html

相关文章:

  • 读懂AUTOSAR :DiagnosticLogAndTrace DLT(四)-- API解析
  • 【LeetCode】剑指 Offer 56. 数组中数字出现的次数 p275 -- Java Version
  • Zookeeper集群 + Fafka集群
  • 全国青少年电子信息智能创新大赛(复赛)python·模拟四卷
  • Redis - 介绍与使用场景
  • Spark SQL实战(07)-Data Sources
  • Django DRF - 权限Permissions
  • 二叉树(OJ)
  • mysql中增删改成的练习
  • 谈一谈Java的ThreadLocal
  • 边缘检测与阈值分割
  • QQ空间无敌装逼,复制下面的任一代码粘贴即可出现意想不到的图案。
  • 必看!总结5种JavaScript异步解决方案
  • JUC并发编程高级篇第四章之ThreadLocal(人手一份,天下安)
  • dump 定位分析
  • (十二)排序算法-插入排序
  • elasticsearch 认知
  • 《人体地图》笔记
  • java基础集合面试题
  • Vue学习-Vue入门
  • 【项目】bxg基于SaaS的餐掌柜项目实战(2023)
  • 灌区流量监测设备-中小灌区节水改造
  • SpringBoot2核心功能 --- 指标监控
  • python实战应用讲解-【numpy数组篇】常用函数(三)(附python示例代码)
  • DIN论文翻译
  • python列表,元组和字典
  • 300元左右的蓝牙耳机哪个好?300左右音质最好的蓝牙耳机
  • 【消息队列】聊一下生产者消息发送流程
  • 特斯拉和OpenAI的加持,马斯克简直人生赢家
  • 优维低代码:第三方接口接入