yarpc

package
v1.0.0-beta2 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2017 License: MIT Imports: 17 Imported by: 0

README

YARPC Module

The RPC module wraps YARPC 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.

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

type DispatcherFn func(service.Host, yarpc.Config) (*yarpc.Dispatcher, error)

DispatcherFn allows override a dispatcher creation, e.g. if it is embedded in another struct.

type Inbound

type Inbound struct {
	TChannel *Address
	HTTP     *Address
}

Inbound is a union that configures how to configure a single inbound.

func (*Inbound) String

func (i *Inbound) String() string

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.

func (*Module) Start

func (m *Module) Start() error

Start begins serving requests with YARPC.

func (*Module) Stop

func (m *Module) Stop() error

Stop shuts down the YARPC module: stops the dispatcher.

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

type ServiceCreateFunc func(svc service.Host) ([]transport.Procedure, error)

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.

Directories

Path Synopsis
Package main is the thriftsync.
Package main is the thriftsync.

Jump to

Keyboard shortcuts

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