client

package
v0.4.5 Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2023 License: MIT Imports: 37 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CallOption

type CallOption func(cc *callConfig)

func WithCallCodec

func WithCallCodec(scheme string) CallOption

func WithCallJsonRpc2

func WithCallJsonRpc2() CallOption

func WithCallJsonRpc2Writer

func WithCallJsonRpc2Writer() CallOption

func WithCallLRPCMuxWriter

func WithCallLRPCMuxWriter() CallOption

func WithCallLRPCNoMuxWriter

func WithCallLRPCNoMuxWriter() CallOption

func WithCallPacker

func WithCallPacker(scheme string) CallOption

func WithCallWriter

func WithCallWriter(writer msgwriter2.Writer) CallOption

type Client

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

Client 在Client中同时使用同步调用和异步调用将导致同步调用阻塞某一连接上的所有异步调用 请求的发送

func New

func New(opts ...Option) (*Client, error)

func (*Client) AsyncCall

func (c *Client) AsyncCall(service string, args []interface{}, callBack func(results []interface{}, err error)) error

AsyncCall TODO 改进这个不合时宜的API AsyncCall 该函数返回时至少数据已经经过Codec的序列化,调用者有责任检查error 该函数可能会传递来自Codec和内部组件的错误,因为它在发送消息之前完成

func (*Client) BindFunc

func (c *Client) BindFunc(sourceName string, i interface{}) error

func (*Client) Call

func (c *Client) Call(service string, args ...interface{}) ([]interface{}, error)

Call 返回的error可能是由Server/Client本身产生的, 也有可能是调用用户过程返回的, 这些都会被Call 视为错误, args为用户参数, 即context.Context & stream.LStream都会被放置在此, 如果存在的话. Call实现context.Context传播的语义, 即传递的Context cancel时, client会同时将server端的 Context cancel, 但不会影响到自身的调用过程, 如果cancel之后, remote process不返回, 那么这次调用将会阻塞 注册了元信息的过程返回的result数量始终等于自身结果数量-1, 因为error不包括在reps中, 不管发生了什么错误, 除非 找不到注册的元信息

func (*Client) Close

func (c *Client) Close() error

func (*Client) RawCall

func (c *Client) RawCall(service string, args ...interface{}) ([]interface{}, error)

RawCall 该调用和Client.Call不同, 这个调用不会识别Method和对应的in/out list 只会对除context.Context/stream.LStream外的args/reps直接序列化

func (*Client) Request

func (c *Client) Request(service string, ctx context.Context, request interface{}, response interface{}, opts ...CallOption) error

Request req/rep风格的RPC调用, 这要求rep必须是指针类型, 否则会返回ErrCallArgsType

func (*Client) Requests

func (c *Client) Requests(service string, requests []interface{}, responses []interface{}, opts ...CallOption) error

Requests multi request and response

type Complete

type Complete struct {
	Message *message.Message
	Error   error2.LErrorDesc
}

type Config

type Config struct {
	// Tls相关的配置
	TlsConfig *tls.Config
	// 服务器的地址
	// 当配置了地址解析器和负载均衡器的时候,此项将被忽略
	ServerAddr string
	// 使用的日志器
	Logger logger.LLogger
	// 连接池中的连接是否使用KeepAlive
	KeepAlive bool
	// 发送ping消息的间隔
	KeepAliveTimeout time.Duration
	// 底层使用的Goroutine池的大小
	PoolSize int32
	// 客户端使用的传输协议
	NetWork string
	// 字节流编码器
	Packer packer.Packer
	// 结构化数据编码器
	Codec codec.Codec
	// 用于连接复用的连接数量
	MuxConnection int
	// 是否开启负载均衡
	OpenLoadBalance bool
	// 使用的负载均衡器
	BalancerFactory balancer.Factory
	// 使用的地址解析器
	ResolverFactory resolver.Factory
	// 负责维护节点连接的选择器
	SelectorFactory selector.Factory
	// 地址解析器解析地址时需要用到的Url
	ResolverParseUrl string
	// 安装的插件
	Plugins []plugin.ClientPlugin
	// 可以生成自定义错误的工厂回调函数
	ErrHandler perror.LErrors
	// 自定义Goroutine Pool的建造器, 在客户端不推荐使用
	// 在不需要使用异步回调模式时可以关闭
	ExecPoolBuilder pool.TaskPoolBuilder[string]
	Writer          msgwriter.Writer
	ParserFactory   msgparser.Factory
	// 是否启用调试模式
	Debug bool
}

type Option

type Option func(config *Config)

func DirectConfig

func DirectConfig(uCfg Config) Option

DirectConfig 这个接口不保证兼容性, 应该谨慎使用 Config中的内容可能会变动, 或者被修改了语义

func WithAddress

func WithAddress(addr string) Option

func WithBalance

func WithBalance(scheme string) Option

func WithCodec

func WithCodec(scheme string) Option

func WithConsistentHashBalance

func WithConsistentHashBalance() Option

func WithCustomLogger

func WithCustomLogger(logger logger.LLogger) Option

func WithDefault

func WithDefault() Option

func WithDefaultKeepAlive

func WithDefaultKeepAlive() Option

func WithErrHandler

func WithErrHandler(eh perror.LErrors) Option

func WithFileResolver

func WithFileResolver(url string) Option

func WithHashLoadBalance

func WithHashLoadBalance() Option

func WithHttpResolver

func WithHttpResolver(url string) Option

func WithJsonRpc2

func WithJsonRpc2() Option

func WithJsonRpc2Writer

func WithJsonRpc2Writer() Option

func WithKeepAlive

func WithKeepAlive(timeOut time.Duration) Option

func WithLiveResolver

func WithLiveResolver(url string) Option

func WithMessageParser

func WithMessageParser(scheme string) Option

func WithMessageWriter

func WithMessageWriter(writer msgwriter2.Writer) Option

func WithMuxConnection

func WithMuxConnection(ok bool) Option

func WithMuxConnectionNumber

func WithMuxConnectionNumber(n int) Option

func WithMuxWriter

func WithMuxWriter() Option

func WithNetWork

func WithNetWork(network string) Option

func WithNoMuxWriter

func WithNoMuxWriter() Option

func WithNoStackTrace

func WithNoStackTrace() Option

func WithOrderSelector

func WithOrderSelector() Option

func WithPacker

func WithPacker(scheme string) Option

func WithPlugin

func WithPlugin(plugin plugin.ClientPlugin) Option

func WithPoolSize

func WithPoolSize(size int) Option

func WithProtocol

func WithProtocol(scheme string) Option

func WithRandomBalance

func WithRandomBalance() Option

func WithRandomSelector

func WithRandomSelector() Option

func WithResolver

func WithResolver(bScheme, url string) Option

func WithRoundRobinBalance

func WithRoundRobinBalance() Option

func WithStackTrace

func WithStackTrace() Option

func WithTlsClient

func WithTlsClient(tlsC *tls.Config) Option

func WithTraitMessageParser

func WithTraitMessageParser() Option

Jump to

Keyboard shortcuts

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