grpc

package module
v1.1.1-0...-01ed168 Latest Latest
Warning

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

Go to latest
Published: Dec 24, 2019 License: MIT Imports: 29 Imported by: 0

README

PHP-GRPC

Latest Stable Version GoDoc Build Status Go Report Card Codecov

PHP-GRPC is an open-source (MIT) high-performance PHP GRPC server build at top of RoadRunner. Server support both PHP and Golang services running within one application.

Features:

  • native Golang GRPC implementation compliant
  • minimal configuration, plug-and-play model
  • very fast, low footprint proxy
  • simple TLS configuration
  • debug tools included
  • Prometheus metrics
  • middleware and server customization support
  • code generation using protoc plugin (go get github.com/spiral/php-grpc/cmd/protoc-gen-php-grpc)
  • transport, message, worker error management
  • response error codes over php exceptions
  • works on Windows

Usage:

Install rr-grpc and protoc-gen-php-grpc by building it or use pre-build binaries.

Define your service schema using proto file. You can scaffold protobuf classes and GRPC service interfaces using:

$ protoc --php_out=target-dir/ --php-grpc_out=target-dir/ sample.proto

Make sure to install protoc compiler and run composer require spiral/php-grpc first

Implement needed classes and create worker.php to invoke your services.

Place .rr.yaml (or any other format supported by viper configurator) into the root of your project. You can run your application now:

$ rr-grpc serve -v -d

To reset workers state:

$ rr-grpc grpc:reset

To show workers statistics:

$ rr-grpc grpc:workers -i

See example.

You can find more details regarding server configuration at RoadRunner Wiki.

License:

MIT License (MIT). Please see LICENSE for more information. Maintained by SpiralScout.

Documentation

Index

Constants

View Source
const EventUnaryCall = 8001

EventUnaryCall thrown after every unary call.

View Source
const ID = "grpc"

ID sets public GRPC service ID for roadrunner.Container.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// Address to listen.
	Listen string

	// Proto file associated with the service.
	Proto string

	// TLS defined authentication method (TLS for now).
	TLS TLS

	// Workers configures roadrunner grpc and worker pool.
	Workers *roadrunner.ServerConfig
}

Config describes GRPC service configuration.

func (*Config) EnableTLS

func (c *Config) EnableTLS() bool

EnableTLS returns true if rr must listen TLS connections.

func (*Config) Hydrate

func (c *Config) Hydrate(cfg service.Config) error

Hydrate the config and validate it's values.

func (*Config) Listener

func (c *Config) Listener() (net.Listener, error)

Listener creates new rpc socket Listener.

func (*Config) Valid

func (c *Config) Valid() error

Valid validates the configuration.

type Proxy

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

Proxy manages GRPC/RoadRunner bridge.

func NewProxy

func NewProxy(name string, metadata string, rr *roadrunner.Server) *Proxy

NewProxy creates new service proxy object.

func (*Proxy) RegisterMethod

func (p *Proxy) RegisterMethod(method string)

RegisterMethod registers new RPC method.

func (*Proxy) ServiceDesc

func (p *Proxy) ServiceDesc() *grpc.ServiceDesc

ServiceDesc returns service description for the proxy.

type Service

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

Service manages set of GPRC services, options and connections.

func (*Service) AddListener

func (svc *Service) AddListener(l func(event int, ctx interface{}))

AddListener attaches grpc event watcher.

func (*Service) AddOption

func (svc *Service) AddOption(opt grpc.ServerOption)

AddOption adds new GRPC server option. Codec and TLS options are controlled by service internally.

func (*Service) AddRRService

func (svc *Service) AddRRService(r func(server *grpc.Server, rr *roadrunner.Server)) error

AddService would be invoked after GRPC service creation.

func (*Service) AddService

func (svc *Service) AddService(r func(server *grpc.Server)) error

AddService would be invoked after GRPC service creation.

func (*Service) AddStreamServerInterceptor

func (svc *Service) AddStreamServerInterceptor(interceptor grpc.StreamServerInterceptor) error

添加stream 拦截器

func (*Service) AddUnaryServerInterceptor

func (svc *Service) AddUnaryServerInterceptor(interceptor grpc.UnaryServerInterceptor) error

添加普通拦截器

func (*Service) Attach

func (svc *Service) Attach(ctr roadrunner.Controller)

Attach attaches cr. Currently only one cr is supported.

func (*Service) Init

func (svc *Service) Init(cfg *Config, r *rpc.Service, e env.Environment) (ok bool, err error)

Init service.

func (*Service) Serve

func (svc *Service) Serve() (err error)

Serve GRPC grpc.

func (*Service) Server

func (svc *Service) Server() *roadrunner.Server

Server returns associated rr server (if any).

func (*Service) Stop

func (svc *Service) Stop()

Stop the service.

type TLS

type TLS struct {
	// Key defined private server key.
	Key string

	// Cert is https certificate.
	Cert string
}

TLS defines auth credentials.

type UnaryCallEvent

type UnaryCallEvent struct {
	// Info contains unary call info.
	Info *grpc.UnaryServerInfo

	// Context associated with the call.
	Context context.Context

	// Error associated with event.
	Error error
	// contains filtered or unexported fields
}

UnaryCallEvent contains information about invoked method.

func (*UnaryCallEvent) Elapsed

func (e *UnaryCallEvent) Elapsed() time.Duration

Elapsed returns duration of the invocation.

type WorkerList

type WorkerList struct {
	// Workers is list of workers.
	Workers []*util.State `json:"workers"`
}

WorkerList contains list of workers.

Directories

Path Synopsis
cmd
example
ext

Jump to

Keyboard shortcuts

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