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 ¶
WithHealthCheckTimeout functional option sets the health check timeout.
func WithProcessTick ¶
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 ¶
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 ¶
GetRandomQuote 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.