rpc

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2021 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Dial

func Dial(serviceAddr string, options ...grpc.DialOption) (*grpc.ClientConn, error)

Dial 客户端直连服务端... 需配合linkerd或istio做负载均衡

func DialWithConsul added in v0.0.2

func DialWithConsul(cr consul.Resource, service string) *grpc.ClientConn

DialWithConsul 客户端通过consul链接服务端

Types

type Config

type Config struct {
	// baseConfig ServiceName
	Name string
	// default tcp
	NetWork string `yaml:"network"`
	Addr    string `yaml:"address"`
	// Host Port build Addr
	Host string `yaml:"host"`
	Port string `yaml:"port"`
	// Timeout is context timeout for per rpc call.
	Timeout time.Duration `yaml:"grpc.timeout"`
	// MaxConnectionIdle is a duration for the amount of time after which an
	// idle connection would be closed by sending a GoAway. Idleness duration
	// is defined since the most recent time the number of outstanding RPCs
	// became zero or the connection establishment.
	MaxConnectionIdle time.Duration `yaml:"grpc.maxConnectionIdle"`
	// MaxConnectionAge is a duration for the maximum amount of time a
	// connection may exist before it will be closed by sending a GoAway. A
	// random jitter of +/-10% will be added to MaxConnectionAge to spread out
	// connection storms.
	MaxConnectionAge time.Duration `yaml:"grpc.maxConnectionAge"`
	// MaxConnectionAgeGrace is an additive period after MaxConnectionAge after
	// which the connection will be forcibly closed.
	MaxConnectionAgeGrace time.Duration `yaml:"grpc.maxConnectionAgeGrace"`
	// After a duration of this time if the server doesn't see any activity it
	// pings the client to see if the transport is still alive.
	// If set below 1s, a minimum value of 1s will be used instead.
	KeepAliveInterval time.Duration `yaml:"grpc.keepaliveInterval"`
	// After having pinged for keepalive check, the server waits for a duration
	// of Timeout and if no activity is seen even after that the connection is
	// closed. default 20s
	KeepAliveTimeout time.Duration `yaml:"grpc.keepaliveTimeout"`
	// Debug mode
	Debug bool
	// DisableAPM 关闭apm
	DisableAPM bool
}

func (*Config) Address

func (c *Config) Address() string

type Server

type Server struct {
	*grpc.Server
	*Config
	// contains filtered or unexported fields
}

func NewServer

func NewServer(cf Config, opt ...grpc.ServerOption) *Server

NewServer return *Server

func (Server) Discovery

func (s Server) Discovery(d discovery.Discovery) error

服务发现 注册服务

func (Server) FadeAway

func (s Server) FadeAway() error

服务发现 注销服务

func (Server) GracefulStop

func (s Server) GracefulStop()

GracefulStop 优雅退出

func (Server) Start

func (s Server) Start() error

func (Server) Stop

func (s Server) Stop()

Stop 直接退出

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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