Programmer’s Guide to Apache Thrift
Randy Abernethy
Foreword by Jens Geyer
  • March 2019
  • ISBN 9781617296161
  • 592 pages
  • printed in black & white

Does a great job of preparing and fine-tuning countless examples to keep pace with the latest developments of the Apache Thrift project.

From the Foreword by Jens Geyer, Apache Thrift PMC Chair

Programmer's Guide to Apache Thrift provides comprehensive coverage of the Apache Thrift framework along with a developer's-eye view of modern distributed application architecture.

About the Technology

Thrift-based distributed software systems are built out of communicating components that use different languages, protocols, and message types. Sitting between them is Thrift, which handles data serialization, transport, and service implementation. Thrift supports many client and server environments and a host of languages ranging from PHP to JavaScript, and from C++ to Go.

About the book

Programmer’s Guide to Apache Thrift provides comprehensive coverage of distributed application communication using the Thrift framework. Packed with code examples and useful insight, this book presents best practices for multi-language distributed development. You’ll take a guided tour through transports, protocols, IDL, and servers as you explore programs in C++, Java, and Python. You’ll also learn how to work with platforms ranging from browser-based clients to enterprise servers.

Table of Contents detailed table of contents

Part 1 Apache Thrift Overview

1 Introduction to Apache Thrift

1.1 Polyglotism, the pleasure and the pain

1.2 Application integration with Apache Thrift

1.2.1 Type serialization

1.2.2 Service implementation

1.3 Building a simple service

1.3.1 The Hello IDL

1.3.2 The Hello server

1.3.3 A Python client

1.3.4 A C++ client

1.3.5 A Java client

1.4 The communications toolkit landscape

1.4.1 SOAP

1.4.2 REST

1.4.3 Protocol Buffers

1.4.4 Apache Avro

1.4.5 Strengths of Apache Thrift

1.4.6 Take away


2 Apache Thrift architecture

2.1 Transports

2.1.1 The Transport interface

2.1.2 End point transports

2.1.3 Layered transports

2.1.4 Server transports

2.2 Protocols

2.3 Apache Thrift IDL

2.3.1 User-defined types and serialization

2.3.2 RPC services

2.4 Servers

2.5 Security


3 Building, testing, and debugging

3.1 Installing the Apache Thrift IDL Compiler

3.1.1 Platform installers

3.1.2 VMs and containers

3.1.3 Building from source

3.2 The Apache Thrift source tree

3.3 Apache Thrift tests

3.4 Debugging RPC services

3.4.1 Examining packets on the wire

3.4.2 Unbuffered interfaces

3.4.3 Interface misalignment

3.4.4 I/O stack misalignment

3.4.5 Instrumenting code

3.4.6 Additional techniques


Part 2 Programming Apache Thrift

4 Moving bytes with transports

4.1 End point transports — part 1: memory & disk

4.1.1 Programming with memory transports

4.1.2 Programming with file transports

4.2 The transport interface

4.2.1 Basic transport operations

4.3 End point transports — Part 2: networks

4.3.1 Network programming with TSocket

4.4 Server transports

4.4.1 Programming network servers with server transports

4.4.2 The Server Transport interface

4.5 Layered transports

4.5.1 Message framing


5 Serializing data with protocols

5.1 Basic serialization with the binary protocol

5.1.1 Using the C++ TBinaryProtocol

5.1.2 Using the Java TBinaryProtocol

5.1.3 Using the Python TBinaryProtocol

5.1.4 Takeaway

5.2 The TProtocol interface

5.2.1 Apache Thrift serialization

5.2.2 C++ TProtocol

5.2.3 Java TProtocol

5.2.4 Python TProtocolBase

5.3 Serializing objects

5.3.1 Struct serialization

5.3.2 Struct deserialization

5.3.3 Struct evolution

5.4 TCompactProtocol

5.5 TJSONProtocol

5.6 Selecting a protocol


6 Apache Thrift IDL

6.1 Interfaces

6.2 Apache Thrift IDL

6.2.1 IDL file names

6.2.2 Element names

6.2.3 Keywords

6.3 The IDL compiler

6.3.1 Compilation phases and error messages

6.3.2 Command line switches

6.4 Comments and documentation

6.5 Namespaces

6.6 Built-in types

6.6.1 Base types

6.6.2 Container types

6.6.3 Literals

6.7 Constants

6.7.1 C++ interface constant implementation

6.7.2 Java interface constant implementation

6.7.3 Python interface constant implementation

6.8 Typedefs

6.9 Enum

6.10 Structures, unions, exceptions, and argument-lists

6.10.1 Structs

6.10.2 Fields

6.10.3 Exceptions

6.10.4 Unions

6.11 Services

6.12 Including external files track.MusicTrack bonusTrack ) }

6.13 Annotations


7 User-defined types

7.1 A simple user-defined type example

7.2 Type design

7.2.1 Namespaces

7.2.2 Constants

7.2.3 Structs

7.2.4 Base types

7.2.5 Typedefs

7.2.6 Field Ids and retiring fields

7.2.7 Enums

7.2.8 Collections

7.2.9 Unions

7.2.10 Requiredness and optional fields

7.3 Serializing objects to disk

7.4 Under the type serialization hood

7.4.1 Serializing with write()

7.4.2 Deserializing with read()

7.5 Type evolution

7.5.1 Renaming fields

7.5.2 Adding fields

7.5.3 Deleting fields

7.5.4 Changing a field’s type

7.5.5 Changing a field’s requiredness

7.5.6 Changing a field’s default value

7.6 Using Zlib compression

7.6.1 Using Zlib with C++

7.6.2 Using Zlib with Python


8 Implementing services

8.1 Declaring IDL services

8.1.1 Parameter identifiers

8.1.2 Parameter Requiredness

8.1.3 Default parameter values

8.1.4 Function and parameter types

8.2 Building a simple service

8.2.1 Interfaces

8.2.2 Coding service handlers and test harnesses

8.2.3 Coding RPC servers

8.2.4 Coding RPC clients

8.3 Service interface evolution

8.3.1 Adding features to a service

8.4 RPC services in depth

8.4.1 Under the hood

8.4.2 Oneway functions

8.4.3 Service inheritance

8.4.4 Asynchronous clients


9 Handling exceptions

9.1 Apache Thrift exceptions

9.2 TTransportException

9.2.1 C++ Exception Processing

9.2.2 Java exception processing

9.2.3 Python exception processing

9.2.4 Error processing without exceptions

9.3 TProtocolException

9.4 TApplicationException

9.5 User-defined exceptions

9.5.1 User-defined exception IDL example

9.5.2 C++ user-defined exception client

9.5.3 C++ user-defined exception server

9.5.4 Java user-defined exception client

9.5.5 Python user-defined exception client


10 Servers

10.1 Building a Simple Server from Scratch

10.2 Using Multithreaded Servers

10.3 Server Concurrency Models

10.3.1 Connection Based Processing

10.3.2 Task Based Processing

10.3.3 Multithreading vs. Multiprocessing

10.3.4 Server Summary by Language

10.4 Using Factories

10.4.1 Building I/O Stacks with Factories

10.4.2 Processor and Handler Factories

10.4.3 In/Out Factories

10.4.4 Building Servers with Custom Factories and Transports

10.5 Server Interfaces and Event Processing

10.5.1 TServer

10.5.2 TServerEventHandler

10.5.3 Building a C++ Thread Pool Server with Server Events

10.6 Servers and Services

10.6.1 Building Multiservice Servers

10.6.2 Building a Multiplexed Java Threaded Selector Server


Part 3 Apache Thrift Languages

11 Building Clients and Servers with C++

11.1 Setting up Apache Thrift for C++ Development

11.1.1 Apache Thrift C++ Versions and Boost

11.1.2 Building Apache Thrift C++ Libraries

11.1.3 Building Apache Thrift C++ Libraries on Windows

11.2 A Simple Client and Server

11.2.1 The Hello IDL

11.2.2 Building a Simple C++ Client

11.2.3 Creating a Simple RPC Server

11.3 C++ Transports, Protocols and Servers

11.3.1 C++ Transports

11.3.2 C++ Protocols

11.3.3 Runtime versus Compile Time Polymorphism

11.3.4 C++ Servers

11.4 The C++ TNonBlockingServer


12 Building Clients and Servers with Java

12.1 Setting up Apache Thrift for Java Development

12.1.1 Apache Thrift and SLF4J

12.2 A Simple Client and Server

12.2.1 The Hello IDL

12.2.2 Building a Simple Java Client

12.2.3 Creating a Simple RPC Server

12.2.4 Building with Ant

12.2.5 Building with Maven

12.3 Using Apache Thrift in other JVM languages

12.4 Java Transports, Protocols and Servers

12.4.1 Java Transports

12.4.2 Java Protocols

12.4.3 Java Servers

12.5 Asynchronous Java RPC


13 Building C# Clients and Servers with .Net and Windows

13.1 Setting up Apache Thrift on Windows

13.2 A Simple Client and Server

13.2.1 Creating a Visual Studio RPC Solution

13.2.2 Creating the Interface Library

13.2.3 Creating the RPC Server

13.2.4 Creating the RPC Client

13.2.5 Testing the RPC Application

13.3 C# Transports, Protocols and Servers

13.3.1 C# Transports

13.3.2 C# Protocols

13.3.3 C# Servers

13.4 Long Polling with Named Pipes

13.4.1 A Long Polling Interface

13.4.2 Installing Apache Thrift Support through NuGet

13.4.3 Creating a Named Pipe Server

13.4.4 Building the Long Polling Server

13.4.5 Building a Named Pipe Client


14 Building Node.js Clients and Servers

14.1 A Simple Client and Server

14.1.1 Generating the Client/Server Stubs

14.1.2 Creating a Node.js Server

14.1.3 Creating a Node.js Client

14.2 Q

14.3 Node.js Servers

14.4 Multiplexed Services

14.5 Apache Thrift IDL and Node.js


15 Apache Thrift and JavaScript

15.1 Apache Thrift JavaScript Quick Start

15.2 A Simple Client and Server

15.2.1 Installing Apache Thrift for JavaScript

15.2.2 The Hello World IDL

15.2.3 The Hello World Node.js Server

15.2.4 The Hello World Web Client

15.2.5 Running the Hello World Example

15.2.6 Debugging

15.2.7 Node.js HTTP Clients

15.3 Asynchronous Browser Client Calls

15.4 RPC Error Handling

15.5 Browser RPC and jQuery

15.6 Apache Thrift and Web Security

15.6.1 Cross-Origin Resource Sharing (CORS)

15.6.2 Content Security Policy (CSP)

15.6.3 X-Frame-Options

15.6.4 Transport Security

15.7 Using the Web Socket Transport


16 Scripting Apache Thrift

16.1 Apache Thrift and Ruby

16.1.1 A Ruby Server

16.1.2 A Ruby Client

16.1.3 Ruby Features

16.2 Apache Thrift and PHP

16.2.1 A PHP Program

16.2.2 A PHP Apache Thrift Client

16.2.3 PHP Features

16.3 Apache Thrift and Perl

16.4 Apache Thrift Perl Clients

16.5 Apache Thrift Perl Servers

16.5.1 Apache Thrift Perl Features

16.6 Apache Thrift and Python


17 Thrift in the Enterprise

17.1 Polyglot Development

17.2 Apache Thrift in the Distributed Landscape

17.2.1 Services

17.2.2 Interface Definition

17.2.3 REST and RPC

17.3 Messaging

17.4 Best Practices

17.4.1 IDL

17.4.2 Interface Evolution

17.4.3 Service Design

17.4.4 Type Design

17.4.5 Coding Practices


What's inside

  • Complete coverage of Thrift’s IDL
  • Building and serializing complex user-defined types
  • Plug-in protocols, transports, and data compression
  • Creating cross-language services with RPC and messaging systems

About the reader

Readers should be comfortable with a language like Python, Java, or C++ and the basics of service-oriented or microservice architectures.

About the author

Randy Abernethy is an Apache Thrift Project Management Committee member and a partner at RX-M.

placing your order...

Don't refresh or navigate away from the page.
print book $35.99 $59.99 pBook + eBook + liveBook
Additional shipping charges may apply
Programmer’s Guide to Apache Thrift (print book) added to cart
continue shopping
go to cart

eBook $33.59 $47.99 3 formats + liveBook
Programmer’s Guide to Apache Thrift (eBook) added to cart
continue shopping
go to cart

Prices displayed in rupees will be charged in USD when you check out.

FREE domestic shipping on three or more pBooks