selector

package
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Feb 6, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewPeerContext

func NewPeerContext(ctx context.Context, p *Peer) context.Context

NewPeerContext creates a new context with peer information attached.

func SetGlobalSelector

func SetGlobalSelector(b Builder)

Types

type Builder

type Builder interface {
	Build() Selector
}

func GlobalSelector

func GlobalSelector() Builder

func NewRandomBuilder

func NewRandomBuilder() Builder

func NewRoundRobinBuilder

func NewRoundRobinBuilder() Builder

func NewWeightRandomBuilder

func NewWeightRandomBuilder() Builder

func NewWeightedRoundRobinBuilder

func NewWeightedRoundRobinBuilder() Builder

type DefaultNode

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

func (*DefaultNode) Address

func (n *DefaultNode) Address() string

Address is node address

func (*DefaultNode) InitialWeight

func (n *DefaultNode) InitialWeight() int64

InitialWeight is node initialWeight

func (*DefaultNode) Metadata

func (n *DefaultNode) Metadata() map[string]string

Metadata is node metadata

func (*DefaultNode) ServiceName

func (n *DefaultNode) ServiceName() string

ServiceName is node serviceName

func (*DefaultNode) Version

func (n *DefaultNode) Version() string

Version is node version

type DoneFunc

type DoneFunc func(ctx context.Context, di DoneInfo)

DoneFunc is callback function when RPC invoke done.

type DoneInfo

type DoneInfo struct {
	// Response Error
	Err error
	// Response Metadata
	ReplyMD ReplyMD

	// BytesSent indicates if any bytes have been sent to the server.
	BytesSent bool
	// BytesReceived indicates if any byte has been received from the server.
	BytesReceived bool
}

type Node

type Node interface {

	// Address is the unique address under the same service
	Address() string

	// ServiceName is service name
	ServiceName() string

	// InitialWeight is the initial value of scheduling weight
	// if not set return nil
	InitialWeight() int64

	// Version is service node version
	Version() string

	// Metadata is the kv pair metadata associated with the service instance.
	// version,namespace,region,protocol etc..
	Metadata() map[string]string
}

func NewNode

func NewNode(addr string, ins *registry.ServiceInstance) Node

NewNode new node

type Peer

type Peer struct {
	// node is the peer node.
	Node Node
}

Peer contains the information of the peer for an RPC, such as the address and authentication information.

func FromPeerContext

func FromPeerContext(ctx context.Context) (p *Peer, ok bool)

FromPeerContext returns the peer information in ctx if it exists.

type RandomBanlance

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

随机

func (*RandomBanlance) Add

func (r *RandomBanlance) Add(nodes ...Node) error

func (*RandomBanlance) Build

func (r *RandomBanlance) Build() Selector

func (*RandomBanlance) Next

func (r *RandomBanlance) Next(ctx context.Context) (selected Node, err error)

随机化负载均衡

type RandomBuilder

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

type ReplyMD

type ReplyMD interface {
	Get(key string) string
}

ReplyMD is Reply Metadata.

type RoundRobin

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

轮询

func (*RoundRobin) Add

func (rr *RoundRobin) Add(nodes ...Node) error

func (*RoundRobin) Next

func (rr *RoundRobin) Next(ctx context.Context) (selected Node, err error)

type RoundRobinBuilder

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

func (*RoundRobinBuilder) Build

func (rr *RoundRobinBuilder) Build() Selector

type Selector

type Selector interface {
	Add(nodes ...Node) error
	Next(ctx context.Context) (selected Node, err error)
}

func NewRandomBanlance

func NewRandomBanlance() Selector

func NewRoundRobin

func NewRoundRobin() Selector

func NewWeightRandomBanlance

func NewWeightRandomBanlance() Selector

func NewWeightedRoundRobin

func NewWeightedRoundRobin() Selector

NewWeightedRoundRobin 创建加权轮询实例

type WeightRandomBanlance

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

加权随机

func (*WeightRandomBanlance) Add

func (wr *WeightRandomBanlance) Add(nodes ...Node) error

func (*WeightRandomBanlance) Build

func (wr *WeightRandomBanlance) Build() Selector

func (*WeightRandomBanlance) Next

func (wr *WeightRandomBanlance) Next(ctx context.Context) (selected Node, err error)

type WeightRandomBuilder

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

type WeightedRoundRobin

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

func (*WeightedRoundRobin) Add

func (w *WeightedRoundRobin) Add(nodes ...Node) error

*

  • 添加所有的当前服务所有的节点

func (*WeightedRoundRobin) Build

func (w *WeightedRoundRobin) Build() Selector

func (*WeightedRoundRobin) Next

func (wrr *WeightedRoundRobin) Next(ctx context.Context) (selected Node, err error)

Next 选择下一个节点

type WeightedRoundRobinBuilder

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

Jump to

Keyboard shortcuts

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