thrift

package
v0.0.0-...-a1a640b Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2015 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package thrift adds support to use Thrift services over TChannel.

To start listening to a Thrift service using TChannel, create the channel, and register the service using:

server := thrift.NewServer(tchan)
server.Register(gen.NewTChan[SERVICE]Server(handler)

// Any number of services can be registered on the same Thrift server.
server.Register(gen.NewTChan[SERVICE2]Server(handler)

To use a Thrift client use the generated TChan client:

thriftClient := thrift.NewClient(ch, "hyperbahnService", nil)
client := gen.NewTChan[SERVICE]Client(thriftClient)

// Any number of service clients can be made using the same Thrift client.
client2 := gen.NewTChan[SERVICE2]Client(thriftClient)

This client can be used similar to a standard Thrift client, except a Context is passed with options (such as timeout).

TODO(prashant): Add and document header support.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ClientOptions

type ClientOptions struct {
	// HostPort specifies a specific server to hit.
	HostPort string
}

ClientOptions are options to customize the client.

type Context

type Context tchannel.ContextWithHeaders

Context is a Thrift Context which contains request and response headers.

func NewContext

func NewContext(timeout time.Duration) (Context, context.CancelFunc)

NewContext returns a Context that can be used to make Thrift calls.

func WithHeaders

func WithHeaders(ctx context.Context, headers map[string]string) Context

WithHeaders returns a Context that can be used to make a call with request headers.

func Wrap

func Wrap(ctx context.Context) Context

Wrap returns a Thrift Context that wraps around a Context.

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server handles incoming TChannel calls and forwards them to the matching TChanServer.

func NewServer

func NewServer(registrar tchannel.Registrar) *Server

NewServer returns a server that can serve thrift services over TChannel.

func (*Server) Handle

func (s *Server) Handle(ctx context.Context, call *tchannel.InboundCall)

Handle handles an incoming TChannel call and forwards it to the correct handler.

func (*Server) Register

func (s *Server) Register(svr TChanServer)

Register registers the given TChanServer to be called on any incoming call for its' services. TODO(prashant): Replace Register call with this call.

type TChanClient

type TChanClient interface {
	// Call should be passed the method to call and the request/response Thrift structs.
	Call(ctx Context, serviceName, methodName string, req, resp thrift.TStruct) (success bool, err error)
}

TChanClient abstracts calling a Thrift endpoint, and is used by the generated client code.

func NewClient

func NewClient(ch *tchannel.Channel, serviceName string, opts *ClientOptions) TChanClient

NewClient returns a Client that makes calls over the given tchannel to the given Hyperbahn service.

type TChanServer

type TChanServer interface {
	// Handle should read the request from the given reqReader, and return the response struct.
	// The arguments returned are success, result struct, unexpected error
	Handle(ctx Context, methodName string, protocol thrift.TProtocol) (success bool, resp thrift.TStruct, err error)

	// Service returns the service name.
	Service() string

	// Methods returns the method names handled by this server.
	Methods() []string
}

TChanServer abstracts handling of an RPC that is implemented by the generated server code.

Directories

Path Synopsis
gen-go
test
Autogenerated by thrift-gen.
Autogenerated by thrift-gen.
thrift-gen generates code for Thrift services that can be used with the uber/tchannel/thrift package.
thrift-gen generates code for Thrift services that can be used with the uber/tchannel/thrift package.

Jump to

Keyboard shortcuts

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