http://thrift.apache.org/
下载thrift-0.6.0
安装看README
需java,要下载ant,加入到path
/*
* 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.
*/
#支持注释#,/***/,//
# Thrift Tutorial
# Mark Slee (mcslee@facebook.com)
#
# This file aims to teach you how to use Thrift, in a .thrift file. Neato. The
# first thing to notice is that .thrift files support standard shell comments.
# This lets you make your thrift file executable and include your Thrift build
# step on the top line. And you can place comments like this anywhere you like.
#
# Before running this file, you will need to have installed the thrift compiler
# into /usr/local/bin.
#类型定义
/**
* The first thing to know about are types. The available types in Thrift are:
*
* bool Boolean, one byte
* byte Signed byte
* i16 Signed 16-bit integer
* i32 Signed 32-bit integer
* i64 Signed 64-bit integer
* double 64-bit floating point value
* string String
* binary Blob (byte array)
* map<t1,t2> Map from one type to another
* list<t1> Ordered list of one type
* set<t1> Set of unique elements of one type
*
* Did you also notice that Thrift supports C style comments?
*/
// Just in case you were wondering... yes. We support simple C comments too.
/**
* Thrift files can reference other Thrift files to include common struct
* and service definitions. These are found using the current path, or by
* searching relative to any paths specified with the -I compiler flag.
*
* Included objects are accessed using the name of the .thrift file as a
* prefix. i.e. shared.SharedObject
*/
include "shared.thrift"
/**
* Thrift files can namespace, package, or prefix their output in various
* target languages.
*/
namespace cpp tutorial
namespace java tutorial
namespace php tutorial
namespace perl tutorial
/**
* Thrift lets you do typedefs to get pretty names for your types. Standard
* C style here.
*/
typedef i32 MyInteger
/**
* Thrift also lets you define constants for use across languages. Complex
* types and structs are specified using JSON notation.
*/
const i32 INT32CONSTANT = 9853
const map<string,string> MAPCONSTANT = {'hello':'world', 'goodnight':'moon'}
/**
* You can define enums, which are just 32 bit integers. Values are optional
* and start at 1 if not supplied, C style again.
*/
enum Operation {
ADD = 1,
SUBTRACT = 2,
MULTIPLY = 3,
DIVIDE = 4
}
/**
* Structs are the basic complex data structures. They are comprised of fields
* which each have an integer identifier, a type, a symbolic name, and an
* optional default value.
*
* Fields can be declared "optional", which ensures they will not be included
* in the serialized output if they aren't set. Note that this requires some
* manual management in some languages.
*/
struct Work {
1: i32 num1 = 0,
2: i32 num2,
3: Operation op,
4: optional string comment,
}
/**
* Structs can also be exceptions, if they are nasty.
*/
exception InvalidOperation {
1: i32 what,
2: string why
}
/**
* 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()
}
/**
* That just about covers the basics. Take a look in the test/ folder for more
* detailed examples. After you run this file, your generated code shows up
* in folders with names gen-<language>. The generated code isn't too scary
* to look at. It even has pretty indentation.
*/
参考
分享到:
相关推荐
Thrift是一种高效的、跨语言的服务框架,最初由Facebook开发,现在是Apache的顶级项目。它提供了强大的代码生成工具,可以从接口定义文件(IDL)生成多种编程语言的客户端和服务端代码,使得不同语言之间可以轻松地...
总之,结合Wireshark和Thrift dissector,我们可以深入洞察Thrift协议的网络交互,这对于开发、调试和维护Thrift服务具有极大的价值。请确保正确配置和使用这些工具,以便充分利用它们的功能,提升你的工作效率。
Thrift是一种开源的跨语言服务开发框架,由Facebook于2007年创建,现在是Apache软件基金会的项目。它的主要目标是通过定义一种中间语言(IDL,Interface Definition Language)来简化不同编程语言之间的通信,使得...
在IT行业中,Thrift是一种高性能、可扩展的跨语言服务开发框架,由Facebook开源,用于构建分布式服务。它通过定义一种中间表示(IDL,接口定义语言)来描述服务,然后自动生成不同编程语言的代码,使得不同语言之间...
Thrift是一种开源的跨语言服务开发框架,由Facebook于2007年创建,并于2008年贡献给了Apache基金会。它通过定义一种中间语言(IDL,Interface Definition Language)来描述服务接口,允许开发者在不同的编程语言之间...
而Thrift则是一种开源的软件框架,用于构建可伸缩的服务,它支持多种编程语言,包括C++,并且允许不同语言之间进行高效的数据交换。在这个“C++(Qt)下的thrift的使用示例”中,我们将探讨如何在Qt项目中集成和使用...
Thrift是一个软件框架,用来进行可扩展且跨语言的服务的开发。它结合了功能强大的软件堆栈和代码生成引擎,以构建在 C++, Java, Python, PHP, Ruby, Erlang, Perl, Haskell, C#, Cocoa, JavaScript, Node.js, ...
在Windows环境下,使用QT结合Thrift进行开发是一项常见的任务,特别是在构建跨平台的服务或应用时。这个样例项目提供了一种方法,使开发者能够在QT环境中有效地利用Thrift框架。让我们详细了解一下这些技术以及如何...
Apache Thrift is an open source cross language serialization and RPC framework. With support for over 15 programming languages, Apache Thrift can play an important role in a range of distributed ...
Thrift SASL 0.3.0 是一个用于在分布式系统中实现安全传输层协议的开源库。Thrift 是一个跨语言的服务开发框架,而SASL(Simple Authentication and Security Layer)则是它的一个扩展,提供了身份验证和数据保护...
### Netty+Thrift 实现高并发高性能的关键技术解析 #### 一、引言 在当前互联网技术高速发展的背景下,高性能、高并发的服务框架成为众多企业和开发者追求的目标。Netty作为一款高性能、异步事件驱动的网络应用...
Thrift 环境配置方法 Thrift 是一个跨语言的 RPC 框架,由 Facebook 开发,用于建立高性能的服务之间的远程过程调用。为了使用 Thrift,需要配置好相关的环境,这篇文章将介绍 Thrift 环境配置的方法。 Thrift ...
Thrift是一种开源的跨语言服务开发框架,由Facebook于2007年创建,并后来贡献给了Apache基金会。它主要用于构建可扩展且高效的分布式系统。Thrift通过定义一种中间表示(IDL,Interface Description Language)来...
在本实例中,我们将关注一个基于Thrift的RPC调用实现,Thrift是由Facebook开发的一种高效的跨语言服务开发框架。 Thrift的核心思想是定义一种中间描述文件(.thrift),该文件包含了服务接口、数据结构以及服务间的...
Thrift是一种开源的跨语言服务开发框架,由Facebook于2007年设计,现在由Apache软件基金会维护。它的主要功能是提供一个定义接口、生成代码和服务通信的工具,简化了分布式系统之间的数据交换。在本资源中,我们讨论...
Thrift是Facebook开源的一款高性能、跨语言的服务框架,它的设计目标是高效地在不同编程语言之间进行通信。本文将基于Thrift的Java实现,总结学习过程中的一些关键知识点,旨在帮助理解Thrift的工作原理以及如何在...
Apache Thrift 是一款由 Facebook 开发的开源框架,主要用于构建跨语言的服务。Thrift 提供了一个集成的代码生成工具,允许开发者定义数据类型和服务接口,然后自动生成多种编程语言(如 C++ 和 Java)的客户端和...
Thrift RPC客户端的服务化框架代码主要涉及了两个关键概念:Thrift和RPC(Remote Procedure Call,远程过程调用)。Thrift是由Facebook开发的一种开源跨语言服务框架,它允许定义数据类型和服务接口,然后自动生成...
在本文中,我们将深入探讨如何使用Java通过Thrift2接口操作HBase数据库。HBase是一个分布式、可扩展的大数据存储系统,它构建于Hadoop之上,支持实时读写。Thrift是一个轻量级的框架,用于跨语言服务开发,允许不同...