thrift

package
v1.0.0-rc1 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2016 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package thrift implements Thrift encoding support for YARPC.

To use this package, you must install ThriftRW 0.2.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
 |- yarpc
     |- myserviceclient
     |- myserviceserver

The client package allows sending requests through a YARPC channel.

client := myserviceclient.New(dispatcher.Channel("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 BuildRegistrants added in v0.4.0

func BuildRegistrants(s Service, opts ...RegisterOption) []transport.Registrant

BuildRegistrants builds a list of Registrants from a Thrift service specification.

func Register deprecated

func Register(r transport.Registrar, rs []transport.Registrant)

Register calls the Registrar's Register method.

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

Deprecated: Use the Registrar's Register method directly.

Types

type Client

type Client interface {
	// Call the given Thrift method.
	Call(ctx context.Context, reqMeta yarpc.CallReqMeta, reqBody envelope.Enveloper) (wire.Value, yarpc.CallResMeta, error)
	CallOneway(ctx context.Context, reqMeta yarpc.CallReqMeta, reqBody envelope.Enveloper) (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(channel, 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

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

Config contains the configuration for the Client.

type OnewayHandler added in v0.4.0

type OnewayHandler interface {
	HandleOneway(ctx context.Context, reqMeta yarpc.ReqMeta, body wire.Value) error
}

OnewayHandler represents a Thrift request handler. It speaks in raw Thrift payloads.

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

type OnewayHandlerFunc added in v0.4.0

type OnewayHandlerFunc func(context.Context, yarpc.ReqMeta, wire.Value) error

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

func (OnewayHandlerFunc) HandleOneway added in v0.4.0

func (f OnewayHandlerFunc) HandleOneway(ctx context.Context, reqMeta yarpc.ReqMeta, body wire.Value) error

HandleOneway forwards the request to the underlying function.

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(channel, 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(channel, 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
	Meta yarpc.ResMeta

	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       map[string]UnaryHandler
	OnewayMethods map[string]OnewayHandler
}

Service is a generic Thrift service implementation.

type UnaryHandler added in v0.4.0

type UnaryHandler interface {
	Handle(ctx context.Context, reqMeta yarpc.ReqMeta, body wire.Value) (Response, error)
}

UnaryHandler represents a Thrift request handler. It speaks in raw Thrift payloads.

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

type UnaryHandlerFunc added in v0.4.0

type UnaryHandlerFunc func(context.Context, yarpc.ReqMeta, wire.Value) (Response, error)

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

func (UnaryHandlerFunc) Handle added in v0.4.0

func (f UnaryHandlerFunc) Handle(ctx context.Context, reqMeta yarpc.ReqMeta, body wire.Value) (Response, error)

Handle forwards the request to the underlying function.

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