- 浏览: 2540898 次
- 性别:
- 来自: 成都
文章分类
最新评论
-
nation:
你好,在部署Mesos+Spark的运行环境时,出现一个现象, ...
Spark(4)Deal with Mesos -
sillycat:
AMAZON Relatedhttps://www.godad ...
AMAZON API Gateway(2)Client Side SSL with NGINX -
sillycat:
sudo usermod -aG docker ec2-use ...
Docker and VirtualBox(1)Set up Shared Disk for Virtual Box -
sillycat:
Every Half an Hour30 * * * * /u ...
Build Home NAS(3)Data Redundancy -
sillycat:
3 List the Cron Job I Have>c ...
Build Home NAS(3)Data Redundancy
Thrift(3)IDL language/Structure and Generate Base Codes
RMI use java seserial to transfer the java object data.
Thrift, same interface and implementation, but it use socket to transfer the data, and we use Object ----> String ----> Object.
So thrift supports many languages.
thrift also can work like this, java object ---> thrift object ---> php object
1. Thrift Introduction
Thrift is IDL(interface definition language) implementation. It works something like CORBA.
Client Server
IDL Stub IDL Skeleton /POA
ORB on Client Side ORB on server side
------> IIOP ----->
Thrift is something like XML-RPC + Java-to-IDL + Serialization Tool. It consist of TProtocol and TTransports. The structure is as follow:
Client Server
Your code Your code
FooService.Client FooService.Proccessor (Generated Code)
Foo.write()/read() Foo.read()/write() (Generated Code)
TProtocol TProtocol
TTransport TTransport
... ...
Underlying I/O Underlying I/O
2. Data Type and Protocol
Base Types
bool : (true or false), one byte
byte
i16
i32
i64
double:
string encoding agnostic text or binary string
Struct
Containers --- List Set Map
list<t1> type is t1, and the collection is ordered, the elements of the collection can be reduplicate.
set<t1> type is t1, not ordered, no reduplicate.
map<t1,t2> key is t1, value is t2
Exception
Services
Comments
# this is a valid comment
/*
* multiple comments
*/
// c++/Java style single-line comments
TProtocol
There are 2 main types, text and binary.
TBinaryProtocol
TCompactProtocol
TJSONProtocol
TSimpleJSONProtocol
TDebugProtocol this is for developing, text.
TTransport
TSocket I/O
TFramedTransport NIO
TFileTransport No java implementation
TMemoryTransport memory I/O, ByteArrayOutputStream
TZlibTransport zlib, No java implementation
Server Types
TSimpleServer single thread I/O
TThreadPoolServer multiple threads I/O
TNonblockingServer multiple threads NIO
3. First Example
java com.sillycat.easytalker.plugins.thrift.gen.code # package name
struct Blog { # POJO
1: string topic
2: binary content
3: i64 createdTime
4: string id
5: string ipAddress
6: map<string,string> props
}
service BlogService { # interface class
string createBlog(1:Blog blog)
list<string> batchCreateBlog(1:list<Blog> blogs)
string deleteBlog(1:string id)
list<Blog> listAll()
Blog getOne(1:string id)
string updateBlog(1:Blog blog)
}
>thrift.exe -out d:\work\easy\easytalker\src\main\java\ -r -gen java BlogService.thrift
Warning Message:
[WARNING:D:/work/easy/easytalker/scripts/thrift/BlogService.thrift:14] No field key specified for blog, resulting protocol may have conflicts or not be backwards compatible!
[WARNING:D:/work/easy/easytalker/scripts/thrift/BlogService.thrift:16] No field key specified for id, resulting protocol may have conflicts or not be backwards compatible!
Solution:
Because we need the number with integer before the properties of struct and parameters of methods.
struct Blog { # POJO
1: string topic
2: binary content
3: i64 createdTime
4: string id
5: string ipAddress
6: map<string,string> props
}
and
list<string> batchCreateBlog(1:list<Blog> blogs)
Once the java code is generate, add this lib to my pom.xml
<dependency>
<groupId>org.apache.thrift</groupId>
<artifactId>libthrift</artifactId>
<version>0.8.0</version>
</dependency>
There are lot of warning message in generated codes.
I tried the following command, but it does not help.
>thrift.exe -out d:\work\easy\easytalker\src\main\java\ -r -gen java:java5 BlogService.thrift
references:
http://gemantic.iteye.com/blog/1199214
http://www.cnblogs.com/birdshover/archive/2010/03/16/1687301.html
http://www.javabloger.com/article/thrift-java-code-example.html
http://www.javabloger.com/article/apache-thrift-architecture.html
http://yangfanchao.iteye.com/blog/1271737
http://thrift.apache.org/docs/idl/
http://thrift.apache.org/docs/types/
http://www.cnblogs.com/tianhuilove/archive/2011/09/05/2167669.html
http://svn.apache.org/repos/asf/thrift/trunk/test/ThriftTest.thrift
http://li3huo.com/2011/10/creating-a-thrift-service-step-by-step/
RMI use java seserial to transfer the java object data.
Thrift, same interface and implementation, but it use socket to transfer the data, and we use Object ----> String ----> Object.
So thrift supports many languages.
thrift also can work like this, java object ---> thrift object ---> php object
1. Thrift Introduction
Thrift is IDL(interface definition language) implementation. It works something like CORBA.
Client Server
IDL Stub IDL Skeleton /POA
ORB on Client Side ORB on server side
------> IIOP ----->
Thrift is something like XML-RPC + Java-to-IDL + Serialization Tool. It consist of TProtocol and TTransports. The structure is as follow:
Client Server
Your code Your code
FooService.Client FooService.Proccessor (Generated Code)
Foo.write()/read() Foo.read()/write() (Generated Code)
TProtocol TProtocol
TTransport TTransport
... ...
Underlying I/O Underlying I/O
2. Data Type and Protocol
Base Types
bool : (true or false), one byte
byte
i16
i32
i64
double:
string encoding agnostic text or binary string
Struct
Containers --- List Set Map
list<t1> type is t1, and the collection is ordered, the elements of the collection can be reduplicate.
set<t1> type is t1, not ordered, no reduplicate.
map<t1,t2> key is t1, value is t2
Exception
Services
Comments
# this is a valid comment
/*
* multiple comments
*/
// c++/Java style single-line comments
TProtocol
There are 2 main types, text and binary.
TBinaryProtocol
TCompactProtocol
TJSONProtocol
TSimpleJSONProtocol
TDebugProtocol this is for developing, text.
TTransport
TSocket I/O
TFramedTransport NIO
TFileTransport No java implementation
TMemoryTransport memory I/O, ByteArrayOutputStream
TZlibTransport zlib, No java implementation
Server Types
TSimpleServer single thread I/O
TThreadPoolServer multiple threads I/O
TNonblockingServer multiple threads NIO
3. First Example
java com.sillycat.easytalker.plugins.thrift.gen.code # package name
struct Blog { # POJO
1: string topic
2: binary content
3: i64 createdTime
4: string id
5: string ipAddress
6: map<string,string> props
}
service BlogService { # interface class
string createBlog(1:Blog blog)
list<string> batchCreateBlog(1:list<Blog> blogs)
string deleteBlog(1:string id)
list<Blog> listAll()
Blog getOne(1:string id)
string updateBlog(1:Blog blog)
}
>thrift.exe -out d:\work\easy\easytalker\src\main\java\ -r -gen java BlogService.thrift
Warning Message:
[WARNING:D:/work/easy/easytalker/scripts/thrift/BlogService.thrift:14] No field key specified for blog, resulting protocol may have conflicts or not be backwards compatible!
[WARNING:D:/work/easy/easytalker/scripts/thrift/BlogService.thrift:16] No field key specified for id, resulting protocol may have conflicts or not be backwards compatible!
Solution:
Because we need the number with integer before the properties of struct and parameters of methods.
struct Blog { # POJO
1: string topic
2: binary content
3: i64 createdTime
4: string id
5: string ipAddress
6: map<string,string> props
}
and
list<string> batchCreateBlog(1:list<Blog> blogs)
Once the java code is generate, add this lib to my pom.xml
<dependency>
<groupId>org.apache.thrift</groupId>
<artifactId>libthrift</artifactId>
<version>0.8.0</version>
</dependency>
There are lot of warning message in generated codes.
I tried the following command, but it does not help.
>thrift.exe -out d:\work\easy\easytalker\src\main\java\ -r -gen java:java5 BlogService.thrift
references:
http://gemantic.iteye.com/blog/1199214
http://www.cnblogs.com/birdshover/archive/2010/03/16/1687301.html
http://www.javabloger.com/article/thrift-java-code-example.html
http://www.javabloger.com/article/apache-thrift-architecture.html
http://yangfanchao.iteye.com/blog/1271737
http://thrift.apache.org/docs/idl/
http://thrift.apache.org/docs/types/
http://www.cnblogs.com/tianhuilove/archive/2011/09/05/2167669.html
http://svn.apache.org/repos/asf/thrift/trunk/test/ThriftTest.thrift
http://li3huo.com/2011/10/creating-a-thrift-service-step-by-step/
发表评论
-
Update Site will come soon
2021-06-02 04:10 1672I am still keep notes my tech n ... -
Hadoop Docker 2019 Version 3.2.1
2019-12-10 07:39 288Hadoop Docker 2019 Version 3.2. ... -
Nginx and Proxy 2019(1)Nginx Enable Lua and Parse JSON
2019-12-03 04:17 439Nginx and Proxy 2019(1)Nginx En ... -
Data Solution 2019(13)Docker Zeppelin Notebook and Memory Configuration
2019-11-09 07:15 279Data Solution 2019(13)Docker Ze ... -
Data Solution 2019(10)Spark Cluster Solution with Zeppelin
2019-10-29 08:37 243Data Solution 2019(10)Spark Clu ... -
AMAZON Kinesis Firehose 2019(1)Firehose Buffer to S3
2019-10-01 10:15 313AMAZON Kinesis Firehose 2019(1) ... -
Rancher and k8s 2019(3)Clean Installation on CentOS7
2019-09-19 23:25 302Rancher and k8s 2019(3)Clean In ... -
Pacemaker 2019(1)Introduction and Installation on CentOS7
2019-09-11 05:48 333Pacemaker 2019(1)Introduction a ... -
Crontab-UI installation and Introduction
2019-08-30 05:54 442Crontab-UI installation and Int ... -
Spiderkeeper 2019(1)Installation and Introduction
2019-08-29 06:49 493Spiderkeeper 2019(1)Installatio ... -
Supervisor 2019(2)Ubuntu and Multiple Services
2019-08-19 10:53 363Supervisor 2019(2)Ubuntu and Mu ... -
Supervisor 2019(1)CentOS 7
2019-08-19 09:33 322Supervisor 2019(1)CentOS 7 Ins ... -
Redis Cluster 2019(3)Redis Cluster on CentOS
2019-08-17 04:07 365Redis Cluster 2019(3)Redis Clus ... -
Amazon Lambda and Version Limit
2019-08-02 01:42 432Amazon Lambda and Version Limit ... -
MySQL HA Solution 2019(1)Master Slave on MySQL 5.7
2019-07-27 22:26 512MySQL HA Solution 2019(1)Master ... -
RabbitMQ Cluster 2019(2)Cluster HA and Proxy
2019-07-11 12:41 456RabbitMQ Cluster 2019(2)Cluster ... -
Running Zeppelin with Nginx Authentication
2019-05-25 21:35 315Running Zeppelin with Nginx Aut ... -
Running Zeppelin with Nginx Authentication
2019-05-25 21:34 316Running Zeppelin with Nginx Aut ... -
ElasticSearch(3)Version Upgrade and Cluster
2019-05-20 05:00 321ElasticSearch(3)Version Upgrade ... -
Jetty Server and Cookie Domain Name
2019-04-28 23:59 389Jetty Server and Cookie Domain ...
相关推荐
从Thrift IDL文件生成TypeScript。 安装 $ npm install --save @creditkarma/thrift-typescript 用法 Thrift TypeScript提供JavaScript和命令行API。 给定以下文件 节俭/简单 struct MyStruct { 1 : required i32...
标题中的"getFinagleThrift"指的是一个特定的项目或工具,它与Apache Thrift和Twitter的Finagle框架相结合,帮助开发者从Thrift IDL(Interface Description Language)文件中自动生成Java代码。Thrift IDL是一种...
它通过定义一种中间语言(IDL,Interface Definition Language)来描述服务接口,然后自动生成各种编程语言的客户端和服务端代码,使得不同语言之间可以方便地进行通信。在 Java 开发环境中,Thrift 主要用于构建高...
mac 想安装低版本thrift 0.9.3太难了,高版本比较简单 直接执行 brew install thrift.rb 即可安装
3. **Thrift服务定义** - 在项目中,通常有一个`.thrift`文件,定义了服务接口和数据结构。例如,`MyService.thrift`可能包含一个`MyService`接口和一些请求/响应类型。 - 接口定义如: ```thrift service ...
2. **Thrift IDL 文件**:在 `src/main/thrift` 目录下,编写 Thrift IDL 文件,定义服务接口和数据结构。例如: ```thrift service MyService { string greet(1: string name) } struct Greeting { 1: required...
3. **服务端实现**:在HBase中,服务端通常是由HBase自身提供的,它实现了Thrift IDL中定义的服务接口,处理客户端的请求。 4. **客户端调用**:在Go中,你可以使用生成的代码来创建客户端,实例化服务代理,然后...
Apache Thrift 是一款由 Facebook 开发的开源框架,主要用于构建跨语言的服务。Thrift 提供了一个集成的代码生成工具,允许开发者定义数据类型和服务接口,然后自动生成多种编程语言(如 C++ 和 Java)的客户端和...
1. IDL(Interface Definition Language):Thrift使用IDL文件定义服务接口和数据类型,类似于protobuf的.proto文件。 2. 编译器:Thrift编译器将IDL文件转换为各种目标语言(如Java、Python、C++等)的代码,包括...
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通过IDL(Interface Definition Language,接口定义语言)来定义RPC(Remote Procedure Call,远程过程调用)的接口和数据类型,然后通过thrift编译器生成不同语言的代码(目前支持C++,Java, Python, PHP, ...
它通过定义一种中间语言(IDL,Interface Definition Language)来描述服务接口,允许开发者在不同的编程语言之间方便地构建和使用RPC(Remote Procedure Call)服务。 在"thrift例子"中,我们主要会接触到以下知识...
thrift-enhancer是一组支持thrift协议的加强包,设计...thrift-translator: 提供动态解析idl并生成参数对象的能力,动态生成的参数对象可以自动转换为thrift协议数据,同时提供 thrift与json、xml的双向转换, 动态解析
它最初设计的目的是解决大规模分布式系统中的数据通信问题,通过定义一种中间表示(IDL,Interface Definition Language)来描述服务接口,然后自动生成不同编程语言的客户端和服务端代码,实现高效、轻量级的通信...
Scrooge 是一个 Thrift 代码解析/生成器,能够生成 Scala 和 Java 代码。这就意味着,它能够取代 Apache Thrift 代码生成器,并能在 libthrift 上生成符合标准的可兼容的二进制编解码。 建议使用Scala语法生成...
Thrift的主要目的是通过定义一种中间表示(IDL,Interface Definition Language)来简化分布式系统之间的通信问题,使得开发者可以在不同的编程语言之间方便地构建服务。在给定的压缩包"thrift-0.9.2.exe"中,包含了...
Thrift通过定义一种中间表示(IDL,Interface Definition Language)来描述服务,允许开发者在不同的语言环境下构建客户端和服务端应用程序。它将接口描述文件编译成特定语言的代码,使得服务提供者和消费者可以使用...
spark-hive_2.11-2.3.0...spark-hive-thriftserver_2.11-2.3.0.jar log4j-2.15.0.jar slf4j-api-1.7.7.jar slf4j-log4j12-1.7.25.jar curator-client-2.4.0.jar curator-framework-2.4.0.jar curator-recipes-2.4.0.jar
编译后的thrift客户端,已经经过公司师父同意分享。 1. cp /Users/dxm/Desktop/thrift /usr/local/bin/ 2. echo $PATH 3. thrift 4. chmod +x /usr/local/bin/thrift 5. thrift 6. thrift -version
export PATH=$PATH:/path/to/thrift/install/bin ``` 在Windows上,通过系统设置界面添加新的系统变量。 4. **测试Thrift** 安装成功后,可以通过运行`thrift --version`命令来检查Thrift是否已经正确安装。...