client

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 11, 2024 License: MIT Imports: 11 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ClientStatus

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

ClientStatus is a client status, which contains the client and the backoff time.

type LBOpt

type LBOpt func(balancer *QuotesLoadBalancer)

LBOpt is a load balancer option.

func WithHealthCheckTimeout

func WithHealthCheckTimeout(timeout time.Duration) LBOpt

WithHealthCheckTimeout functional option sets the health check timeout.

func WithProcessTick

func WithProcessTick(tick time.Duration) LBOpt

WithProcessTick functional option sets the process tick.

type LoadBalancer

type LoadBalancer interface {
	Next() RPCQuoteser
	ProcessClients()
}

LoadBalancer is a load balancer interface, which contains the next method and the process clients method.

type NoAvailableClientsError

type NoAvailableClientsError struct {
}

NoAvailableClientsError ошибка отсутствия доступных клиентов

func (*NoAvailableClientsError) Error

func (e *NoAvailableClientsError) Error() string

Error возвращает текст ошибки

type QuotesClient

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

QuotesClient имплементация rpc клиента цитат

func NewQuotesClient

func NewQuotesClient(addr string) *QuotesClient

NewQuotesClient конструктор rpc клиента цитат

func (*QuotesClient) GetRandomQuote

func (q *QuotesClient) GetRandomQuote(ctx context.Context) (entity.QuoteDTO, error)

GetRandomQuote rpc запрос на получение случайной цитаты

func (*QuotesClient) HealthCheck

func (q *QuotesClient) HealthCheck(ctx context.Context) error

HealthCheck rpc запрос на проверку доступности клиента

type QuotesLB

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

QuotesLB имплементация клиента цитат с балансировкой

func NewQuotesClientLB

func NewQuotesClientLB(log *zap.Logger, balancer LoadBalancer) *QuotesLB

NewQuotesClientLB конструктор клиента цитат с балансировкой

func (*QuotesLB) GetRandomQuote

func (q *QuotesLB) GetRandomQuote(ctx context.Context) (entity.QuoteDTO, error)

GetRandomQuote rpc запрос на получение случайной цитаты

func (*QuotesLB) HealthCheck

func (q *QuotesLB) HealthCheck(ctx context.Context) error

HealthCheck rpc запрос на проверку доступности клиента

type QuotesLoadBalancer

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

QuotesLoadBalancer implements the LoadBalancer interface. inactiveClients - the inactive clients list of Quotes grpc clients. activeClients - the active clients list of Quotes grpc clients. processTick - the process tick, which is used for processing alive and dead clients. healthCheckTimeout - the health check timeout, which is used for checking the health of the clients. nextIndex - the next index for the next client, which is used for the round-robin algorithm. initialBackoff - the initial backoff time, which is used for the exponential backoff algorithm. maxBackoff - the maximum backoff time, which is used for the exponential backoff algorithm. mux - the mutex for the thread safety.

func NewLoadBalancer

func NewLoadBalancer(clientsPool []RPCQuoteser, opts ...LBOpt) *QuotesLoadBalancer

NewLoadBalancer creates a new load balancer.

func (*QuotesLoadBalancer) Eliminate

func (r *QuotesLoadBalancer) Eliminate()

Eliminate eliminates the inactive clients, if they are unhealthy.

func (*QuotesLoadBalancer) Next

func (r *QuotesLoadBalancer) Next() RPCQuoteser

Next returns the next client, which is used for the round-robin algorithm.

func (*QuotesLoadBalancer) ProcessClients

func (r *QuotesLoadBalancer) ProcessClients()

ProcessClients processes the clients.

func (*QuotesLoadBalancer) Recover

func (r *QuotesLoadBalancer) Recover()

Recover recovers the inactive clients, if they are healthy.

type RPCQuoteser

type RPCQuoteser interface {
	GetRandomQuote(ctx context.Context) (entity.QuoteDTO, error)
	HealthCheck(ctx context.Context) error
}

RPCQuoteser интерфейс rpc для клиента цитат

Jump to

Keyboard shortcuts

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