grpc

package module
Version: v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2021 License: MIT Imports: 33 Imported by: 1

README

PHP-GRPC

Latest Stable Version GoDoc Build Status Go Report Card Total alerts 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.

Documentation:

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

	// see .rr.yaml for the explanations
	MaxSendMsgSize        int64
	MaxRecvMsgSize        int64
	MaxConnectionIdle     time.Duration
	MaxConnectionAge      time.Duration
	MaxConnectionAgeGrace time.Duration
	MaxConcurrentStreams  int64
	PingTime              time.Duration
	Timeout               time.Duration
}

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) AddService

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

AddService would be invoked after GRPC service creation.

func (*Service) Attach added in v1.0.7

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 added in v1.0.8

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

	// Root CA
	RootCA string
}

TLS defines auth credentials.

type UnaryCallEvent added in v1.0.8

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 added in v1.0.8

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.

Jump to

Keyboard shortcuts

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