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 ¶
- func ReadHeaders(r io.Reader) (map[string]string, error)
- func ReadStruct(reader io.Reader, s thrift.TStruct) error
- func WriteHeaders(w io.Writer, headers map[string]string) error
- func WriteStruct(writer io.Writer, s thrift.TStruct) error
- type ClientOptions
- type Context
- type HealthFunc
- type PostResponseCB
- type RegisterOption
- type Server
- type TChanClient
- type TChanServer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ReadHeaders ¶ added in v1.0.1
ReadHeaders reads key-value pairs encoded using WriteHeaders.
func ReadStruct ¶ added in v1.0.1
ReadStruct reads the given Thrift struct. It pools TProtocols.
func WriteHeaders ¶ added in v1.0.1
WriteHeaders writes the given key-value pairs using the following encoding: len~2 (k~4 v~4)~len
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 ¶
WithHeaders returns a Context that can be used to make a call with request headers.
type HealthFunc ¶
HealthFunc is the interface for custom health endpoints. ok is whether the service health is OK, and message is optional additional information for the health result.
type PostResponseCB ¶
PostResponseCB registers a callback that is run after a response has been compeltely processed (e.g. written to the channel). This gives the server a chance to clean up resources from the response object
type RegisterOption ¶
type RegisterOption interface {
Apply(h *handler)
}
RegisterOption is the interface for options to Register.
func OptPostResponse ¶
func OptPostResponse(cb PostResponseCB) RegisterOption
OptPostResponse registers a PostResponseCB.
type Server ¶
Server handles incoming TChannel calls and forwards them to the matching TChanServer.
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, opts ...RegisterOption)
Register registers the given TChanServer to be called on any incoming call for its' services. TODO(prashant): Replace Register call with this call.
func (*Server) RegisterHealthHandler ¶
func (s *Server) RegisterHealthHandler(f HealthFunc)
RegisterHealthHandler uses the user-specified function f for the Health endpoint.
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 athrift.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 athrift.TProtocol) (success bool, resp athrift.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.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
benchclient is used to make requests to a specific server.
|
benchclient is used to make requests to a specific server. |
gen-go
|
|
test
Package test is generated code used to make or handle TChannel calls using Thrift.
|
Package test is generated code used to make or handle TChannel calls using Thrift. |
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. |