thrift文件服务器,Apache

2023-11-17

The Apache Thrift software framework, for scalable cross-language services development, combines a software stack with a code generation engine to build services that work efficiently and seamlessly between C++, Java, Python, PHP, Ruby, Erlang, Perl, Haskell, C#, Cocoa, JavaScript, Node.js, Smalltalk, OCaml and Delphi and other languages.

Getting Started

Download Apache Thrift

To get started, download a copy of Thrift.

Build and Install the Apache Thrift compiler

You will then need to build the Apache Thrift compiler and install it. See the installing Thrift guide for any help with this step.

Writing a .thrift file

After the Thrift compiler is installed you will need to create a thrift file. This file is an interface definition made up of thrift types and Services. The services you define in this file are implemented by the server and are called by any clients. The Thrift compiler is used to generate your Thrift File into source code which is used by the different client libraries and the server you write. To generate the source from a thrift file run

thrift --gen

The sample tutorial.thrift file used for all the client and server tutorials can be found here.

To learn more about Apache Thrift Read the Whitepaper

Example

Apache Thrift allows you to define data types and service interfaces in a simple definition file. Taking that file as input, the compiler generates code to be used to easily build RPC clients and servers that communicate seamlessly across programming languages. Instead of writing a load of boilerplate code to serialize and transport your objects and invoke remote methods, you can get right down to business.

The following example is a simple service to store user objects for a web front end.

/**

* Ahh, now onto the cool part, defining a service. Services just need a name

* and can optionally inherit from another service using the extends keyword.

*/

service Calculator extends shared.SharedService {

/**

* A method definition looks like C code. It has a return type, arguments,

* and optionally a list of exceptions that it may throw. Note that argument

* lists and exception lists are specified using the exact same syntax as

* field lists in struct or exception definitions.

*/

void ping(),

i32 add(1:i32 num1, 2:i32 num2),

i32 calculate(1:i32 logid, 2:Work w) throws (1:InvalidOperation ouch),

/**

* This method has a oneway modifier. That means the client only makes

* a request and does not listen for any response at all. Oneway methods

* must be void.

*/

oneway void zip()

}

This snippet was generated by Apache Thrift's source tree docs:

tutorial/tutorial.thrift

def main():

# Make socket transport = TSocket.TSocket('localhost', 9090)

# Buffering is critical. Raw sockets are very slow transport = TTransport.TBufferedTransport(transport)

# Wrap in a protocol protocol = TBinaryProtocol.TBinaryProtocol(transport)

# Create a client to use the protocol encoder client = Calculator.Client(protocol)

# Connect! transport.open()

client.ping()

print('ping()')

sum_ = client.add(1, 1)

This snippet was generated by Apache Thrift's source tree docs:

tutorial/py/PythonClient.py

Initialize the Server:

try {

TServerTransport serverTransport = new TServerSocket(9090);

TServer server = new TSimpleServer(new Args(serverTransport).processor(processor));

// Use this for a multithreaded server

// TServer server = new TThreadPoolServer(new TThreadPoolServer.Args(serverTransport).processor(processor));

System.out.println("Starting the simple server...");

server.serve();

} catch (Exception e) {

e.printStackTrace();

}

This snippet was generated by Apache Thrift's source tree docs:

tutorial/java/src/JavaServer.java

The CalculatorHandler:

public class CalculatorHandler implements Calculator.Iface {

private HashMap log;

public CalculatorHandler() {

log = new HashMap();

}

public void ping() {

System.out.println("ping()");

}

public int add(int n1, int n2) {

System.out.println("add(" + n1 + "," + n2 + ")");

return n1 + n2;

}

public int calculate(int logid, Work work) throws InvalidOperation {

System.out.println("calculate(" + logid + ", {" + work.op + "," + work.num1 + "," + work.num2 + "})");

int val = 0;

switch (work.op) {

case ADD:

val = work.num1 + work.num2;

break;

case SUBTRACT:

val = work.num1 - work.num2;

break;

case MULTIPLY:

val = work.num1 * work.num2;

break;

case DIVIDE:

if (work.num2 == 0) {

InvalidOperation io = new InvalidOperation();

io.whatOp = work.op.getValue();

io.why = "Cannot divide by 0";

throw io;

}

val = work.num1 / work.num2;

break;

default:

InvalidOperation io = new InvalidOperation();

io.whatOp = work.op.getValue();

io.why = "Unknown operation";

throw io;

}

SharedStruct entry = new SharedStruct();

entry.key = logid;

entry.value = Integer.toString(val);

log.put(logid, entry);

return val;

}

public SharedStruct getStruct(int key) {

System.out.println("getStruct(" + key + ")");

return log.get(key);

}

public void zip() {

System.out.println("zip()");

}

}

This snippet was generated by Apache Thrift's source tree docs:

tutorial/java/src/CalculatorHandler.java

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

thrift文件服务器,Apache 的相关文章

  • android 登陆界面

    LoginActivity java package com example ruian import android app Activity import android app AlertDialog import android c
  • 用python将结果存进csv文件中

    def writeCsv File species row File species out open data test csv a newline csv writer csv writer out dialect excel csv
  • 代码走查和代码审查_这是经过1000多次代码审查后我学到的东西

    代码走查和代码审查 这个故事最初发表在我的博客上 如果您对这种内容感兴趣 请随时签出并订阅 在过去的三年中 我已经审查了1000多个请求 合并 请求 在那段时间里 我学到了很多东西 主要是关于如何不审阅代码 如何减轻过程的痛苦 使高质量的代
  • python字典中的值只能是字符串类型_python字典key不能是可以是啥类型

    python中字典的key不能是可变类型 字典可存储任意类型对象 其中值可以取任何数据类型 但键必须是不可变的 如字符串 数字或元组 语法格式 d key1 value1 key2 value2 字典是另一种可变容器模型 且可存储任意类型对
  • 神经搜索有多能?

    原文 Alex C G 译文 Piper Hu 本文阅读时长约为5分钟 神经搜索 是数据处理上非常新颖的一个话题 也是Jina AI目前着重关注的方向 可是到底神经搜索是什么 它能解决什么问题 与现在开发者们使用的搜索系统搭建又有什么不一样
  • javaScript节流与防抖

    一 节流 throttle 用来实现阻止在短时间内重复多次触发同一个函数 主要用途 防止使用脚本循环触发网络请求的函数的恶意行为 确保请求的真实性 当然也包括其他阻止高频触发行为的应用 实现原理图 代码实现 1 节流函数 2 functio
  • python中xpath解析网页html文档

    1 首先安装xpath解析工具第三方库 pip install i https pypi tuna tsinghua edu cn simple lxml 2 选取节点 选取未知节点 选取若干路径 举例说明 谓语用来查找某个特定的节点或者包
  • 三子棋(人机对战)

    目录 整体思路 头文件如下 为什么要使用头文件呢 头文件的使用 游戏主函数如下 功能实现如下 注意 整体思路 1 创建一个二维数组 2 初始化二维数组 3 打印棋盘 4 玩家下棋且打印棋盘 5 电脑下棋且打印棋盘 6 判断输赢 头文件如下
  • 智能合约概述——以太坊虚拟机

    以太坊虚拟机 概述 以太坊虚拟机 EVM 是智能合约的运行环境 它不仅是沙盒封装的 而且是完全隔离的 也就是说在 EVM 中运行代码是无法访问网络 文件系统和其他进程的 甚至智能合约之间的访问也是受限的 账户 以太坊中有两类账户 它们共用同
  • springmvc 项目本地开发正常,war 上了 wins下的tomcat,web 页面中文乱码

    前言 今天打包 springmvc 项目 war 包 windows 下 tomcat 运行 浏览器访问乱码 解决方案 tomcat bin 目录下 catalina bat 文件中添加 set JAVA OPTS Dfile encodi
  • 区块链之元宇宙

    区块链之元宇宙 元宇宙概念 元宇宙 Metaverse 是利用科技手段进行链接与创造的 与现实世界映射和交互的虚拟世界 具备新型社会体系的数字生活空间 元宇宙本质上是对现实世界的虚拟化 数字化过程 需要对内容生产 经济系统 用户体验以及实体
  • 智能教育装备法则

    二十一世纪 在互联网 大数据 智慧教育等新科技的带动下 我国教育信息化教育信息化产业规模将以每年平15 的速度增长 格物斯坦表示 有越来越多智能教育装备的后起之秀企业开启了他们的研发软件和硬件的能力 教育的信息化首先是教育装备的信息化和智慧
  • 浅析瀑布流布局及其原理

    一 什么是瀑布流 瀑布流 又被称作为瀑布流式布局 是一种比较流行的网站页面布局方式 视觉表现为参差不齐的多栏布局 随着页面滚动条向下滚动 这种布局还会不断加载数据块并附加至当前尾部 这种布局方式常见于一些图片为主的网站 为什么要使用瀑布流
  • 关于QT5.12.0在VS2019上使用的细节

    关于QT5 12 0在VS2019上的使用细节 博主使用的版本 QT5 12 0 VS2019 其他Qt版本同样适用 1 添加Qt的环境变量 在Win10下 编辑系统环境变量 环境变量 Path 新建添加Qt的bin目录路径 D QT 12
  • Burpsuite Professional 2023.6.2 最新版安装教程

    更新时间 2023年07月23日11 47 48 本文以mac为例 Windows上方法是类似的 1 缘由 因为我用的Burpsuite版本有点老 导致有时候给人培训的时候 面对新版Burpsuite一脸懵逼 很多操作都不太一样 所以这次直
  • 从零开始 verilog 以太网交换机(七)总结与展望

    从零开始 verilog 以太网交换机 七 总结与展望 声明 博主主页 王 嘻嘻的CSDN主页 从零开始 verilog 以太网交换机系列专栏 点击这里 未经作者允许 禁止转载 侵权必删 关注本专题的朋友们可以收获一个经典交换机设计的全流程
  • Trinitycore学习之在vscode查看远端服务器上源码配置

    1 安装vscode 去官网下载 这里下载windows版本安装包 zip https code visualstudio com Download 2 安装后 安装扩展chinese 使用中文设置 需要重启vscode 3 安装ssh相关
  • 报错:‘wget‘ 不是内部或外部命令,也不是可运行的程序

    在jupyter lab下使用wegt 导入需要用到的数据集 wget https tianchi media oss cn beijing aliyuncs com DSW 7XGBoost train csv wget 不是内部或外部命
  • 终端zsh_只需七个步骤,即可使您的“ ZSH”终端站起来—直观指南

    终端zsh by rajaraodv 通过rajaraodv 只需七个步骤 即可使您的 ZSH 终端站起来 直观指南 Jazz Up Your ZSH Terminal In Seven Steps A Visual Guide In th

随机推荐

  • 设置PHP的fpm的系统性能参数pm.max_children

    1 介绍 PHP从Apache module换成了Fpm 跑了几天突然发现网站打不开了 页面显示超时 检查MySQL Redis一众服务都正常 进入Fpm容器查看日志 发现了如下的错误信息 server reached pm max chi
  • day05 java_Spring IoC 和 DI

    为什么使用spring框架 1 解耦代码 每次使用都要new一个对象 2 解决事务繁琐问题 创建对象 初始化 调用方法 销毁对象 3 使用第三方框架麻烦的问题 总结 spring是一个轻量级的Ioc Di和AOP容器 轻量级 简洁 高效 低
  • 面试官偷偷给到45k*16薪,堪称面试风向标!

    前天加完班 回家路上翻了下粉丝群 发现群里最近在疯传一份叫 前端offer收割机养成指南 的资料 本来感觉这个title看起来有点离谱 结果没想到仔细一看 这份资料竟然真的有点东西 内容收纳的很全 而且融合了很多今年的新玩意 据我所知有人靠
  • HTML 整体缩放

    最近用到web 控件加载网页需要缩放问题 由于控件比较旧 所以只能从html 入手 html 页面缩放主要有两种 IE 可使用 CSS body zoom 1 2 或者微软相关的控件支持 包括BCB 其它 浏览器可使用 body trans
  • 指针字符串 与 const char * 即const * char 的详细使用讲解

    指针字符串的使用问题 一 直接定义字符串指针的使用注意事项 定义字符串指针的时候 const char 和字符串本身相同 就不会出现警告 const char char const 作用 const char p 表示的是指针p指向的数值不
  • Kubernetes CoreDNS 状态是 CrashLoopBackOff 报错

    查看状态的时候 遇见coredns出现crashlookbackoff 首先我们来进行排错 不管是什么原因 查看coredns的详细信息 以及logs root k8s master coredns kubectl get pod svc
  • Shell 中 &>/dev/null 和 >/dev/null 2>&1

    下面 咱们一起来看看这个命令操作涉及到的知识点 这其实涉及到三部分的内容 如下图 1 文件描述符 linux shell脚本攻略 的描述 文件描述符是与文件输入 输出关联的整数 它们用来跟踪已打开的文件 最常见的文件描述符是 stidin
  • linux cuda安装目录,Ubuntu 11.10上安装CUDA开发环境的方法及命令

    这篇文章全部内容在我的ThinkPad W520 Ubuntu 11 10 x64位上测试通过 但不代表这篇文章的内容适合你 任何根据这篇文章操作产生的后果 这篇文章作者cheungmine概不负责 英文参考文档 http develope
  • 华为OD机试 C++ [周末爬山]

    题目 小明打算周末去爬山 有一份山的地图 上面用数字表示山的高度 0表示平地 1至9表示不同的山峰高度 小明每次移动只能上下左右移动一格 并且山峰高度差不能超过k 现在他从地图的左上角出发 你能帮他找出他能爬到的最高的山峰是多高吗 还有 他
  • Android数据存储 —— SharedPreferences

    SharedPreferences以键值对的形式存储数据 支持几种基本数据类型 boolean float int long String 一般存储配置信息 它保存的数据时持久化的 即使应用被关掉也不会丢失 存储格式为 xml 一般放在内部
  • 三十二、java版 SpringCloud分布式微服务云架构之Java LinkedList

    Java LinkedList 链表 Linked list 是一种常见的基础数据结构 是一种线性表 但是并不会按线性的顺序存储数据 而是在每一个节点里存到下一个节点的地址 链表可分为单向链表和双向链表 一个单向链表包含两个值 当前节点的值
  • IO流作业

    io 文件操作 in 读取 out 写出 java io File 常用的三个构造方法 File String pathname 通过将给定的路径名字符串转换为抽象路径名来创建新的 File实例 public class Demo01 pu
  • 目标检测方法概述(一)

    目标检测的问题 就是在给定的图片中找到物体的位置 并标明物体的类别 通过卷积神经网络CNN 我们可以完成图像识别 即分类任务 然后我们需要通过一些额外的功能完成定位任务 即找到上图中方框在图像中的位置 x y w
  • Webshell不出网方案之正向socks代理reGeorg+Proxifier使用

    参考博客 https blog csdn net God XiangYu article details 100126207 Regeorg地址 https github com sensepost reGeorg Proxifier地址
  • 从 Java 到 Go:构建社交网络平台后端的过渡之旅

    目录 目录 1 项目概述 2 环境准备 2 1 安装依赖 3 从 Java 到 Go 的基础知识
  • 屏幕分辨率dpi解析(adb 调试查看)

    author daisy skye的博客 CSDN博客 嵌入式 Qt Linux领域博主 ro sf lcd density属性指定了这个机型使用的dpi是多少 dpi全称是dots per inch 对角线每英寸的像素点的个数 密度 ld
  • [从零开始学习FPGA编程-21]:进阶篇 - 架构 - VerilogHDL编码规范

    作者主页 文火冰糖的硅基工坊 文火冰糖 王文兵 的博客 文火冰糖的硅基工坊 CSDN博客 本文网址 目录 前言 第1章 标识符的编码规范 1 1 模块名与文件名
  • excel相乘再相加_(excel 两列相乘再相加)excel表格两列数据乘积

    Excel求两列的乘积用什么公式啊 1 Excel 2016电子表格应用程序 所示点击屏幕右侧新建空作簿 2 选中销售额单元格数域 如图所示 选择 公式 函数库 功能区 点击 插入函数 图标 3 唤出 插入函数 对话框 点击 搜索函数或选择
  • 2020年团体程序设计天梯赛-总决赛 L2-2 口罩发放

    L2 2 口罩发放 25分 输入格式 输出格式 输入样例 输出样例 样例解释 题解 L2 2 口罩发放 25分 为了抗击来势汹汹的 COVID19 新型冠状病毒 全国各地均启动了各项措施控制疫情发展 其中一个重要的环节是口罩的发放 某市出于
  • thrift文件服务器,Apache

    The Apache Thrift software framework for scalable cross language services development combines a software stack with a c