client

package
v2.6.0 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2024 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Actor

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

Actor defines a given actor name and kind

func NewActor

func NewActor(kind string) *Actor

NewActor creates an instance of Actor

func (*Actor) Kind

func (x *Actor) Kind() string

Kind returns the actor kind

func (*Actor) Name

func (x *Actor) Name() string

Name returns the actor name

func (*Actor) WithName

func (x *Actor) WithName(name string) *Actor

WithName set the given name

type Balancer

type Balancer interface {
	// Set sets the balancer nodes pool
	Set(nodes ...*Node)
	// Next returns the appropriate weight-balanced node to use
	Next() *Node
}

Balancer helps locate the right node to channel Client request to

type BalancerStrategy

type BalancerStrategy int

BalancerStrategy defines the Client weight balancer strategy

const (
	// RoundRobinStrategy uses the round-robin algorithm to determine the appropriate node
	RoundRobinStrategy BalancerStrategy = iota
	// RandomStrategy uses the random algorithm to determine the appropriate node
	RandomStrategy
	// LeastLoadStrategy choses among a pool of nodes the node that has the less weight
	// at the time of the execution
	LeastLoadStrategy
)

type Client

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

Client connects to af Go-Akt nodes. This client can only be used when remoting is enabled on the various nodes. The client is only used against a Go-Akt cluster

func New

func New(ctx context.Context, addresses []string, opts ...Option) (*Client, error)

New creates an instance of Client. The provided nodes are the cluster nodes. A node is the form of host:port where host and port represents the remoting host and remoting port of the nodes. The nodes list will be load balanced based upon the load-balancing strategy defined by default round-robin will be used. An instance of the Client can be reused and it is thread safe.

func (*Client) Ask

func (x *Client) Ask(ctx context.Context, actor *Actor, message proto.Message, timeout time.Duration) (reply proto.Message, err error)

Ask sends a message to a given actor provided the actor name and expects a response. If the given actor does not exist it will be created automatically when Client mode is enabled. This will block until a response is received or timed out.

func (*Client) Close

func (x *Client) Close()

Close closes the Client connection

func (*Client) Kinds

func (x *Client) Kinds(ctx context.Context) ([]string, error)

Kinds returns the list of all the Client kinds registered

func (*Client) ReSpawn added in v2.2.2

func (x *Client) ReSpawn(ctx context.Context, actor *Actor) (err error)

ReSpawn restarts a given actor

func (*Client) Spawn

func (x *Client) Spawn(ctx context.Context, actor *Actor) (err error)

Spawn creates an actor provided the actor name.

func (*Client) SpawnWithBalancer added in v2.2.2

func (x *Client) SpawnWithBalancer(ctx context.Context, actor *Actor, strategy BalancerStrategy) (err error)

SpawnWithBalancer creates an actor provided the actor name and the balancer strategy

func (*Client) Stop

func (x *Client) Stop(ctx context.Context, actor *Actor) error

Stop stops or kills a given actor in the Client

func (*Client) Tell

func (x *Client) Tell(ctx context.Context, actor *Actor, message proto.Message) error

Tell sends a message to a given actor provided the actor name. If the given actor does not exist it will be created automatically when Client mode is enabled

func (*Client) Whereis

func (x *Client) Whereis(ctx context.Context, actor *Actor) (*goaktpb.Address, error)

Whereis finds and returns the address of a given actor

type LeastLoad

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

LeastLoad uses the LeastLoadStrategy to pick the next available node in the pool

func NewLeastLoad

func NewLeastLoad() *LeastLoad

NewLeastLoad creates an instance of LeastLoad

func (*LeastLoad) Next

func (x *LeastLoad) Next() *Node

Next returns the next node in the pool

func (*LeastLoad) Set

func (x *LeastLoad) Set(nodes ...*Node)

Set sets the balancer nodes pool

type Node

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

Node represents the node in the cluster

func NewNode

func NewNode(address string, weight int) *Node

NewNode creates an instance of Node

func (*Node) Address

func (n *Node) Address() string

Address returns the node address

func (*Node) SetWeight

func (n *Node) SetWeight(weight float64)

SetWeight sets the node weight. This is thread safe

func (*Node) Weight

func (n *Node) Weight() float64

Weight returns the node weight

type Option

type Option interface {
	// Apply sets the Option value of a config.
	Apply(cl *Client)
}

Option is the interface that applies a configuration option.

func WithBalancerStrategy

func WithBalancerStrategy(strategy BalancerStrategy) Option

WithBalancerStrategy sets the Client weight balancer strategy

func WithRefresh

func WithRefresh(interval time.Duration) Option

WithRefresh sets a refresh interval. This help check the nodes state time to time. This help remove dead nodes from the pool

type OptionFunc

type OptionFunc func(*Client)

OptionFunc implements the Option interface.

func (OptionFunc) Apply

func (f OptionFunc) Apply(c *Client)

type Random

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

Random helps pick a node at random

func NewRandom

func NewRandom() *Random

NewRandom creates an instance of Random balancer

func (*Random) Next

func (x *Random) Next() *Node

Next returns the next node in the pool

func (*Random) Set

func (x *Random) Set(nodes ...*Node)

Set sets the balancer nodes pool

type RoundRobin

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

RoundRobin implements the round-robin algorithm to pick a particular nodes in the cluster

func NewRoundRobin

func NewRoundRobin() *RoundRobin

NewRoundRobin creates an instance of RoundRobin

func (*RoundRobin) Next

func (x *RoundRobin) Next() *Node

Next returns the next node in the pool

func (*RoundRobin) Set

func (x *RoundRobin) Set(nodes ...*Node)

Set sets the balancer nodes pool

Jump to

Keyboard shortcuts

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