rpc

package
v0.0.0-...-15bed1d Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2022 License: Apache-2.0 Imports: 6 Imported by: 0

README

rpc

RPC只是描绘了 Client 与 Server 之间的点对点调用流程,包括 stub、通信、RPC 消息解析等部分, 在实际应用中,还需要考虑服务的高可用、负载均衡等问题,所以产品级的 RPC 框架除了点对点的 RPC 协议的具体实现外, 还应包括服务的发现与注销、提供服务的多台 Server 的负载均衡、服务的高可用等更多的功能。 目前的 RPC 框架大致有两种不同的侧重方向,一种偏重于服务治理,另一种偏重于跨语言调用。

服务治理型的 RPC 框架有 Dubbo、DubboX、Motan、rpcx 等

这类的 RPC 框架的特点是功能丰富,提供高性能的远程调用以及服务发现及治理功能, 适用于大型服务的微服务化拆分以及管理,对于特定语言(Java)的项目可以十分友好的透明化接入。 但缺点是语言耦合度较高,跨语言支持难度较大。

跨语言调用型的 RPC 框架有 Thrift、gRPC、Hessian、Hprose 等

这一类的 RPC 框架重点关注于服务的跨语言调用,能够支持大部分的语言进行语言无关的调用, 非常适合于为不同语言提供通用远程服务的场景。但这类框架没有服务发现相关机制, 实际使用时一般需要代理层进行请求转发和负载均衡策略控制。

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type RPC

type RPC struct {
	Enable       bool   `yaml:"enable" default:"false"`
	Scheme       string `yaml:"scheme" default:"tcp" opts:"tcp"`
	Host         string `yaml:"host" default:""`
	Port         int    `yaml:"port" default:"8972"`
	TLS          TLS    `yaml:"tls"`
	ReadTimeout  int    `yaml:"readTimeout" default:"5"`
	WriteTimeout int    `yaml:"writeTimeout" default:"5"`
	KeepAlive    int    `yaml:"keepAlive" default:"120"`
}

type RegisterIns

type RegisterIns interface {
	ServiceName() string
	Metadata() string
}

RegisterIns 可导出的注册方法

type RegisterRPC

type RegisterRPC func(server *Server) error

type Server

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

func NewServer

func NewServer(cfg RPC) (*Server, error)

func (*Server) Register

func (s *Server) Register(ins RegisterIns)

func (*Server) Run

func (s *Server) Run(ctx context.Context) error

type TLS

type TLS struct {
	Enable bool   `yaml:"enable" default:"false"`
	Key    string `yaml:"key"`
	Cert   string `yaml:"cert"`
}

Jump to

Keyboard shortcuts

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