Documentation
¶
Overview ¶
Package yarpc is the YARPC Module.
The RPC module wraps YARPC (https://github.com/yarpc/yarpc-go) and exposes creators for both JSON- and Thrift-encoded messages.
This module works in a way that's pretty similar to existing RPC projects:
• Create an IDL file and run the appropriate tools on it (e.g. **thriftrw**) to generate the service and handler interfaces
• Implement the service interface handlers as method receivers on a struct
• Implement a top-level function, conforming to the yarpc.ServiceCreateFunc signature (fx/modules/yarpc/yarpc.go that returns a []transport.Registrant YARPC implementation from the handler:
func NewMyServiceHandler(svc service.Host) ([]transport.Registrant, error) { return myservice.New(&MyServiceHandler{}), nil }
• Pass that method into the module initialization:
func main() { svc, err := service.WithModule( yarpc.New(yarpc.ServiceCreateFunc(NewMyServiceHandler)), service.WithModuleRole("service"), ).Build() if err != nil { log.Fatal("Could not initialize service: ", err) } svc.Start(true) }
This will spin up the service.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func New ¶
func New(hookup ServiceCreateFunc, options ...ModuleOption) service.ModuleProvider
New creates a YARPC Module from a service func
func RegisterDispatcher ¶
func RegisterDispatcher(dispatchFn DispatcherFn)
RegisterDispatcher allows you to override the YARPC dispatcher registration
func RegisterStarter ¶
func RegisterStarter(startFn StarterFn)
RegisterStarter allows you to override function that starts a dispatcher.
Types ¶
type Address ¶
type Address struct {
Port int
}
Address is a struct that have a required port for tchannel/http transports. TODO(alsam) make it optional
type DispatcherFn ¶
DispatcherFn allows override a dispatcher creation, e.g. if it is embedded in another struct.
type Module ¶
type Module struct {
// contains filtered or unexported fields
}
Module is an implementation of a core RPC module using YARPC. All the YARPC modules share the same dispatcher and middleware. Dispatcher will start when any created module calls Start(). The YARPC team advised dispatcher to be a 'singleton' to control the lifecycle of all of the in/out bound traffic, so we will register it in a dig.Graph provided with options/default graph.
type ModuleOption ¶
type ModuleOption func(*moduleOptions) error
ModuleOption is a function that configures module creation.
func WithInboundMiddleware ¶
func WithInboundMiddleware(i ...middleware.UnaryInbound) ModuleOption
WithInboundMiddleware adds custom YARPC inboundMiddleware to the module
func WithOnewayInboundMiddleware ¶
func WithOnewayInboundMiddleware(i ...middleware.OnewayInbound) ModuleOption
WithOnewayInboundMiddleware adds custom YARPC inboundMiddleware to the module
type ServiceCreateFunc ¶
ServiceCreateFunc creates a YARPC service from a service host
type StarterFn ¶
type StarterFn func(dispatcher *yarpc.Dispatcher) error
StarterFn overrides start for dispatcher, e.g. attach some metrics with start.