xclient

package
v0.0.0-...-1b68696 Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2021 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Discovery

type Discovery interface {
	// 从注册中心更新服务列表
	Refresh() error
	Update(servers []string) error
	Get(mode SelectMode) (string, error)
	GetAll() ([]string, error)
}

type DrpcRegistryDiscovery

type DrpcRegistryDiscovery struct {
	*MultiServerDiscovery
	// contains filtered or unexported fields
}

func NewDrpcRegistryDiscovery

func NewDrpcRegistryDiscovery(registry string, timeout time.Duration) *DrpcRegistryDiscovery

NewDrpcRegistryDiscovery do

func (*DrpcRegistryDiscovery) Get

func (dr *DrpcRegistryDiscovery) Get(mode SelectMode) (string, error)

Get 和 GetAll 与 MultiServersDiscovery 相似, 唯一的不同在于,GeeRegistryDiscovery 需要先调用 Refresh 确保服务列表没有过期。

func (*DrpcRegistryDiscovery) GetAll

func (dr *DrpcRegistryDiscovery) GetAll() ([]string, error)

func (*DrpcRegistryDiscovery) Refresh

func (dr *DrpcRegistryDiscovery) Refresh() error

Refresh do

func (*DrpcRegistryDiscovery) Update

func (dr *DrpcRegistryDiscovery) Update(servers []string) error

Update update server list

type MultiServerDiscovery

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

func NewMultiServerDiscovery

func NewMultiServerDiscovery(servers []string) *MultiServerDiscovery

func (*MultiServerDiscovery) Get

func (d *MultiServerDiscovery) Get(mode SelectMode) (string, error)

Get gets a server by mode

func (*MultiServerDiscovery) GetAll

func (d *MultiServerDiscovery) GetAll() ([]string, error)

GetAll return all the servers in discovery

func (*MultiServerDiscovery) Refresh

func (d *MultiServerDiscovery) Refresh() error

Refresh do what???

func (*MultiServerDiscovery) Update

func (d *MultiServerDiscovery) Update(servers []string) error

Update updates the servers of discovery dynamically if necessary

type SelectMode

type SelectMode int
const (
	RandomSelect     SelectMode = iota // select randomly
	RoundRobinSelect                   // select using Robbin algorithm
)

type XClient

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

XClient is a client that supports load balance

func NewXClient

func NewXClient(d Discovery, mode SelectMode, opt *Option) *XClient

NewXClient 的构造函数需要传入三个参数, * 服务发现实例 Discovery * 负载均衡模式 SelectMode * 协议选项 Option 为了尽量地复用已经创建好的 Socket 连接,使用 clients 保存创建成功的 Client 实例, 并提供 Close 方法。用于在结束后,关闭已经建立的所有连接

func (*XClient) BroadCast

func (xc *XClient) BroadCast(ctx context.Context, serviceMethod string, args, ret interface{}) error

BroadCast invokes the named function for every server registered in discovery

func (*XClient) Call

func (xc *XClient) Call(ctx context.Context, serviceMethod string, args, ret interface{}) error

Call invokes the named function, waits for it to complete, and returns its error status. xc will choose a proper server.

func (*XClient) Close

func (xc *XClient) Close() error

Jump to

Keyboard shortcuts

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