rpc

package
v0.0.0-...-e43fadc Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2021 License: Apache-2.0 Imports: 15 Imported by: 1

Documentation

Index

Constants

View Source
const (
	//RoundRobin 轮询负载算法
	RoundRobin = iota + 1
	//LocalFirst 本地优先负载算法
	LocalFirst
)

Variables

This section is empty.

Functions

func ResolvePath

func ResolvePath(address string, d string, s string) (service string, domain string, server string, err error)

ResolvePath 解析注册中心地址 order.request#merchant_api.parrot 解析为:service: /order/request,server:merchant_api,domain:parrot order.request 解析为 service: /order/request,server:merchant_cron,domain:parrot order.request#merchant_rpc 解析为 service: /order/request,server:merchant_rpc,domain:parrot

Types

type BalancerMode

type BalancerMode struct {
	Mode  int
	Param string
}

type Client

type Client struct {
	IsConnect bool
	// contains filtered or unexported fields
}

Client rpc client, 用于构建基础的RPC调用,并提供基于服务器的限流工具,轮询、本地优先等多种负载算法

func NewClient

func NewClient(address string, opts ...ClientOption) (*Client, error)

NewClient 创建RPC客户端,地址是远程RPC服务器地址或注册中心地址

func (*Client) Close

func (c *Client) Close()

Close 关闭RPC客户端连接

func (*Client) Request

func (c *Client) Request(service string, method string, header map[string]string, form map[string]interface{}, failFast bool) (status int, result string, param map[string]string, err error)

Request 发送Request请求

func (*Client) UpdateLimiter

func (c *Client) UpdateLimiter(limit map[string]int) error

UpdateLimiter 修改服务器限流规则

type ClientOption

type ClientOption func(*clientOption)

ClientOption 客户端配置选项

func WithBalancer

func WithBalancer(service string, lb balancer.CustomerBalancer) ClientOption

WithBalancer 设置负载均衡器

func WithConnectionTimeout

func WithConnectionTimeout(t time.Duration) ClientOption

WithConnectionTimeout 配置网络连接超时时长

func WithLocalFirstBalancer

func WithLocalFirstBalancer(r balancer.ServiceResolver, service string, local string, limit map[string]int) ClientOption

WithLocalFirstBalancer 配置为本地优先负载均衡器

func WithLogger

func WithLogger(log *logger.Logger) ClientOption

WithLogger 配置日志记录器

func WithRoundRobinBalancer

func WithRoundRobinBalancer(r balancer.ServiceResolver, service string, timeout time.Duration, limit map[string]int) ClientOption

WithRoundRobinBalancer 配置为轮询负载均衡器

func WithTLS

func WithTLS(tls []string) ClientOption

WithTLS 设置TLS证书(pem,key)

type Invoker

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

Invoker RPC服务调用器,封装基于域及负载算法的RPC客户端

func NewInvoker

func NewInvoker(domain string, server string, address string, opts ...InvokerOption) (f *Invoker)

NewInvoker 构建RPC服务调用器 domain: 当前服务所在域 server: 当前服务器名称 addrss: 注册中心地址格式: zk://192.168.0.1166:2181或standalone://localhost

func (*Invoker) AsyncRequest

func (r *Invoker) AsyncRequest(service string, method string, header map[string]string, form map[string]interface{}, failFast bool) rpc.IRPCResponse

AsyncRequest 发起异步Request请求

func (*Invoker) Close

func (r *Invoker) Close()

Close 关闭当前客户端与服务器的连接

func (*Invoker) GetClient

func (r *Invoker) GetClient(addr string) (c *Client, err error)

GetClient 获取RPC客户端 addr 支持格式: order.request#merchant.parrot order.request,order.request@api.parrot order.request@api

func (*Invoker) PreInit

func (r *Invoker) PreInit(services ...string) (err error)

PreInit 预初始化服务器连接

func (*Invoker) Request

func (r *Invoker) Request(service string, method string, header map[string]string, form map[string]interface{}, failFast bool) (status int, result string, params map[string]string, err error)

Request 使用RPC调用Request函数

func (*Invoker) RequestFailRetry

func (r *Invoker) RequestFailRetry(service string, method string, header map[string]string, form map[string]interface{}, times int) (status int, result string, params map[string]string, err error)

RequestFailRetry 失败重试请求

func (*Invoker) WaitWithFailFast

func (r *Invoker) WaitWithFailFast(callback func(string, int, string, error), timeout time.Duration, rs ...rpc.IRPCResponse) error

WaitWithFailFast 快速失败,当有一个请求返回失败后不再等待其它请求,直接返回失败

type InvokerOption

type InvokerOption func(*invokerOption)

InvokerOption 客户端配置选项

func WithBalancerMode

func WithBalancerMode(platName string, mode int, p string) InvokerOption

func WithInvokerLogger

func WithInvokerLogger(log *logger.Logger) InvokerOption

WithInvokerLogger 设置日志记录器

func WithLocalFirst

func WithLocalFirst(prefix string, platName ...string) InvokerOption

WithLocalFirst 设置为本地优先负载

func WithRPCTLS

func WithRPCTLS(platName string, tls []string) InvokerOption

WithRPCTLS 设置TLS证书(pem,key)

func WithRoundRobin

func WithRoundRobin(platName ...string) InvokerOption

WithRoundRobin 设置为轮询负载

type Response

type Response struct {
	Service string
	Result  chan rpc.IRPCResult
}

Response 异步请求的响应内容

func NewResponse

func NewResponse(service string) *Response

NewResponse 构建异步请求响应

func (*Response) GetResult

func (r *Response) GetResult() chan rpc.IRPCResult

GetResult 获取响应的近观回结果

func (*Response) GetService

func (r *Response) GetService() string

GetService 获取服务

func (*Response) Wait

func (r *Response) Wait(timeout time.Duration) (int, string, map[string]string, error)

Wait 等待请求返回

type Result

type Result struct {
	Service string
	Status  int
	Result  string
	Params  map[string]string
	Err     error
}

Result 请求执行结果

func (*Result) GetErr

func (r *Result) GetErr() error

GetErr 获取执行错误信息

func (*Result) GetParams

func (r *Result) GetParams() map[string]string

GetParams 获取执行结果

func (*Result) GetResult

func (r *Result) GetResult() string

GetResult 获取执行结果

func (*Result) GetService

func (r *Result) GetService() string

GetService 获取服务名称

func (*Result) GetStatus

func (r *Result) GetStatus() int

GetStatus 获取状态码

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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