thrift

package
v1.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 11, 2017 License: MIT Imports: 14 Imported by: 5

Documentation

Overview

Package thrift implements Thrift encoding support for YARPC.

To use this package, you must install ThriftRW 1.0 or newer.

go get go.uber.org/thriftrw

You must also install the ThriftRW plugin for YARPC.

go get go.uber.org/yarpc/encoding/thrift/thriftrw-plugin-yarpc

To generate YARPC compatible code from a Thrift file, use the command,

thriftrw --plugin yarpc myservice.thrift

In addition to generating code for types specified in your Thrift file, this will generate two packages for each service in the file: a client package and a server package.

myservice
   |- myserviceclient
   |- myserviceserver

The client package allows sending requests through a YARPC dispatcher.

client := myserviceclient.New(dispatcher.ClientConfig("myservice"))

The server package facilitates registration of service implementations with a YARPC dispatcher.

handler := myHandler{}
dispatcher.Register(myserviceserver.New(handler))

Index

Constants

View Source
const Encoding transport.Encoding = "thrift"

Encoding is the name of this encoding.

Variables

This section is empty.

Functions

func BuildProcedures added in v1.0.0

func BuildProcedures(s Service, opts ...RegisterOption) []transport.Procedure

BuildProcedures builds a list of Procedures from a Thrift service specification.

func Register deprecated

func Register(r transport.RouteTable, rs []transport.Procedure)

Register calls the RouteTable's Register method.

This function exists for backwards compatibility only. It will be removed in a future version.

Deprecated: Use the RouteTable's Register method directly.

Types

type Client

type Client interface {
	// Call the given Thrift method.
	Call(ctx context.Context, reqBody envelope.Enveloper, opts ...yarpc.CallOption) (wire.Value, error)
	CallOneway(ctx context.Context, reqBody envelope.Enveloper, opts ...yarpc.CallOption) (transport.Ack, error)
}

Client is a generic Thrift client. It speaks in raw Thrift payloads.

Users should use the client generated by the code generator rather than using this directly.

func New

func New(c Config, opts ...ClientOption) Client

New creates a new Thrift client.

type ClientOption

type ClientOption interface {
	// contains filtered or unexported methods
}

ClientOption customizes the behavior of a Thrift client.

var Multiplexed ClientOption = multiplexedOption{}

Multiplexed is an option that specifies that requests from a client should use Thrift multiplexing. This option should be used if the remote server is using Thrift's TMultiplexedProtocol. It includes the name of the service in the envelope name for all outbound requests.

Specify this option when constructing the Thrift client.

client := myserviceclient.New(clientConfig, thrift.Multiplexed)

type Config

type Config struct {
	// Name of the Thrift service. This is the name used in the Thrift file
	// with the 'service' keyword.
	Service string

	// ClientConfig through which requests will be sent. Required.
	ClientConfig transport.ClientConfig
}

Config contains the configuration for the Client.

type HandlerSpec added in v1.0.0

type HandlerSpec struct {
	Type   transport.Type
	Unary  UnaryHandler
	Oneway OnewayHandler
}

HandlerSpec represents the handler behind a Thrift service method.

type Method added in v1.0.0

type Method struct {
	// Name of the method itself.
	Name string

	// The handler to call.
	HandlerSpec HandlerSpec

	// Snippet of Go code representing the function definition of the handler.
	// This is useful for introspection.
	Signature string
}

Method represents a Thrift service method.

type OnewayHandler added in v0.4.0

type OnewayHandler func(context.Context, wire.Value) error

OnewayHandler is a convenience type alias for functions that act as OnewayHandlers.

type Option

type Option interface {
	ClientOption
	RegisterOption
}

Option unifies options that apply to both, Thrift clients and handlers.

var Enveloped Option = envelopedOption{}

Enveloped is an option that specifies that Thrift requests and responses should be enveloped. It defaults to false.

It may be specified on the client side when the client is constructed.

client := myserviceclient.New(clientConfig, thrift.Enveloped)

It may be specified on the server side when the handler is registered.

dispatcher.Register(myserviceserver.New(handler, thrift.Enveloped))

Note that you will need to enable enveloping to communicate with Apache Thrift HTTP servers.

func Protocol added in v0.4.0

func Protocol(p protocol.Protocol) Option

Protocol is an option that specifies which Thrift Protocol servers and clients should use. It may be specified on the client side when the client is constructed,

client := myserviceclient.New(clientConfig, thrift.Protocol(protocol.Binary))

It may be specified on the server side when the handler is registered.

dispatcher.Register(myserviceserver.New(handler, thrift.Protocol(protocol.Binary)))

It defaults to the Binary protocol.

type RegisterOption

type RegisterOption interface {
	// contains filtered or unexported methods
}

RegisterOption customizes the behavior of a Thrift handler during registration.

type Response

type Response struct {
	Body envelope.Enveloper

	IsApplicationError bool
}

Response contains the raw response from a generated Thrift handler.

type Service

type Service struct {
	// Name of the Thrift service. This is the name specified for the service
	// in the IDL.
	Name    string
	Methods []Method
}

Service is a generic Thrift service implementation.

type UnaryHandler added in v0.4.0

type UnaryHandler func(context.Context, wire.Value) (Response, error)

UnaryHandler is a convenience type alias for functions that act as Handlers.

Directories

Path Synopsis
thriftrw-plugin-yarpc implements a plugin for ThriftRW that generates code compatible with YARPC.
thriftrw-plugin-yarpc implements a plugin for ThriftRW that generates code compatible with YARPC.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL