client

package
v1.0.0-beta Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2022 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// DefaultBodyCodec 默认的消息编码
	DefaultBodyCodec = "json"
	// DefaultSessionAge 默认session会话生命周期
	DefaultSessionAge = time.Duration(0)
	// DefaultContextAge 默认单次请求生命周期
	DefaultContextAge = time.Duration(0)
	// DefaultDialTimeout 作为客户端角色时,请求服务端的超时时间
	DefaultDialTimeout = time.Second * 5
	// DefaultSlowCometDuration 慢处理定义时间
	DefaultSlowCometDuration = time.Duration(0)
	// DefaultRetryTimes 默认重试次数
	DefaultRetryTimes = 2

	// RerClientClosed 客户端已关闭错误信息
	RerClientClosed = drpc.NewStatus(100, "client is closed", "")
)

Functions

This section is empty.

Types

type Option

type Option func(*Options)

func BodyCodec

func BodyCodec(c string) Option

func ContextAge

func ContextAge(n time.Duration) Option

func CountTime

func CountTime(c bool) Option

func DialTimeout

func DialTimeout(n time.Duration) Option

func GlobalLeftPlugin

func GlobalLeftPlugin(plugin ...drpc.Plugin) Option

GlobalLeftPlugin 设置插件

func HeartbeatTime

func HeartbeatTime(t time.Duration) Option

HeartbeatTime 设置心跳包时间

func LocalIP

func LocalIP(addr string) Option

func Network

func Network(net string) Option

func PrintDetail

func PrintDetail(c bool) Option

func ProtoFunc

func ProtoFunc(pf proto.ProtoFunc) Option

ProtoFunc 设置协议方法

func Registry

func Registry(r registry.Registry) Option

Registry 设置服务注册中心

func RetryTimes

func RetryTimes(n int) Option

RetryTimes 设置重试次数

func Selector

func Selector(s selector.Selector) Option

Selector 设置选择器

func SessionAge

func SessionAge(n time.Duration) Option

func SlowCometDuration

func SlowCometDuration(n time.Duration) Option

func TlsConfig

func TlsConfig(config *tls.Config) Option

TlsConfig 设置证书对象

func TlsFile

func TlsFile(tlsCertFile string, tlsKeyFile string) Option

TlsFile 设置证书内容

type Options

type Options struct {
	Context           context.Context // 上下文
	Network           string          // 网络类型
	LocalIP           string          // 本地网络
	TlsCertFile       string
	TlsKeyFile        string
	TLSConfig         *tls.Config
	ProtoFunc         proto.ProtoFunc
	SessionAge        time.Duration
	ContextAge        time.Duration
	DialTimeout       time.Duration
	SlowCometDuration time.Duration
	BodyCodec         string
	PrintDetail       bool
	CountTime         bool
	HeartbeatTime     time.Duration
	Registry          registry.Registry
	Selector          selector.Selector
	RetryTimes        int
	GlobalLeftPlugin  []drpc.Plugin
}

func NewOptions

func NewOptions(options ...Option) Options

NewOptions 初始化配置

func (*Options) EndpointConfig

func (that *Options) EndpointConfig() drpc.EndpointConfig

type RpcClient

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

RpcClient rpc客户端结构体

func NewRpcClient

func NewRpcClient(serviceName string, opt ...Option) *RpcClient

NewRpcClient 创建rpc客户端

func (*RpcClient) AsyncCall

func (that *RpcClient) AsyncCall(serviceMethod string, arg interface{}, result interface{}, callCmdChan chan<- drpc.CallCmd, setting ...message.MsgSetting) drpc.CallCmd

AsyncCall 异步请求

func (*RpcClient) Call

func (that *RpcClient) Call(serviceMethod string, args interface{}, result interface{}, setting ...message.MsgSetting) drpc.CallCmd

Call 请求服务端

func (*RpcClient) Close

func (that *RpcClient) Close()

Close 关闭客户端对象

func (*RpcClient) Endpoint

func (that *RpcClient) Endpoint() drpc.Endpoint

Endpoint 返回Endpoint对象

func (*RpcClient) Options

func (that *RpcClient) Options() Options

Options 获取配置信息

func (*RpcClient) Push

func (that *RpcClient) Push(serviceMethod string, arg interface{}, setting ...message.MsgSetting) *drpc.Status

Push 发送push消息

func (*RpcClient) RoutePush

func (that *RpcClient) RoutePush(ctrlStruct interface{}, plugin ...drpc.Plugin) []string

RoutePush 使用结构体注册PUSH处理程序,并且返回地址

func (*RpcClient) RoutePushFunc

func (that *RpcClient) RoutePushFunc(pushHandleFunc interface{}, plugin ...drpc.Plugin) string

RoutePushFunc 使用函数注册PUSH处理程序,并且返回地址

func (*RpcClient) SubRoute

func (that *RpcClient) SubRoute(pathPrefix string, plugin ...drpc.Plugin) *drpc.SubRouter

SubRoute 设置服务的路由组

Jump to

Keyboard shortcuts

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