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
- func BuildRegistrants(s Service, opts ...RegisterOption) []transport.Registrant
- func Register(r transport.Registrar, rs []transport.Registrant)deprecated
- type Client
- type ClientOption
- type Config
- type OnewayHandler
- type OnewayHandlerFunc
- type Option
- type RegisterOption
- type Response
- type Service
- type UnaryHandler
- type UnaryHandlerFunc
Constants ¶
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.
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
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
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 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
UnaryHandlerFunc is a convenience type alias for functions that act as Handlers.
Source Files ¶
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. |