Documentation ¶
Index ¶
- Constants
- func ResolvePath(address string, d string, s string) (service string, domain string, server string, err error)
- type BalancerMode
- type Client
- type ClientOption
- func WithBalancer(service string, lb balancer.CustomerBalancer) ClientOption
- func WithConnectionTimeout(t time.Duration) ClientOption
- func WithLocalFirstBalancer(r balancer.ServiceResolver, service string, local string, limit map[string]int) ClientOption
- func WithLogger(log *logger.Logger) ClientOption
- func WithRoundRobinBalancer(r balancer.ServiceResolver, service string, timeout time.Duration, ...) ClientOption
- func WithTLS(tls []string) ClientOption
- type Invoker
- func (r *Invoker) AsyncRequest(service string, method string, header map[string]string, ...) rpc.IRPCResponse
- func (r *Invoker) Close()
- func (r *Invoker) GetClient(addr string) (c *Client, err error)
- func (r *Invoker) PreInit(services ...string) (err error)
- func (r *Invoker) Request(service string, method string, header map[string]string, ...) (status int, result string, params map[string]string, err error)
- func (r *Invoker) RequestFailRetry(service string, method string, header map[string]string, ...) (status int, result string, params map[string]string, err error)
- func (r *Invoker) WaitWithFailFast(callback func(string, int, string, error), timeout time.Duration, ...) error
- type InvokerOption
- func WithBalancerMode(platName string, mode int, p string) InvokerOption
- func WithInvokerLogger(log *logger.Logger) InvokerOption
- func WithLocalFirst(prefix string, platName ...string) InvokerOption
- func WithRPCTLS(platName string, tls []string) InvokerOption
- func WithRoundRobin(platName ...string) InvokerOption
- type Response
- type Result
Constants ¶
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 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服务器地址或注册中心地址
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 WithRoundRobinBalancer ¶
func WithRoundRobinBalancer(r balancer.ServiceResolver, service string, timeout time.Duration, limit map[string]int) ClientOption
WithRoundRobinBalancer 配置为轮询负载均衡器
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) GetClient ¶
GetClient 获取RPC客户端 addr 支持格式: order.request#merchant.parrot order.request,order.request@api.parrot order.request@api
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函数
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)
type Response ¶
type Response struct { Service string Result chan rpc.IRPCResult }
Response 异步请求的响应内容
func (*Response) GetResult ¶
func (r *Response) GetResult() chan rpc.IRPCResult
GetResult 获取响应的近观回结果