Documentation ¶
Overview ¶
Package loadbalance is a way to load balance service nodes
Index ¶
- Constants
- Variables
- func GetStrategyPlugin(name string) (func([]*registry.MicroServiceInstance, interface{}) Next, error)
- func InstallStrategy(name string, strategy func([]*registry.MicroServiceInstance, interface{}) Next)
- type Filter
- type LBError
- type Next
- type Option
- type Options
- type SelectOption
- type SelectOptions
- type Selector
- type Strategy
Constants ¶
const (
ZoneAware = "zoneaware"
)
constant string for zoneaware
Variables ¶
var ( // ErrNoneAvailable is to represent load balance error ErrNoneAvailable = LBError{Message: "No available"} )
Functions ¶
func GetStrategyPlugin ¶
func GetStrategyPlugin(name string) (func([]*registry.MicroServiceInstance, interface{}) Next, error)
GetStrategyPlugin get strategy plugin
func InstallStrategy ¶
func InstallStrategy(name string, strategy func([]*registry.MicroServiceInstance, interface{}) Next)
InstallStrategy install strategy
Types ¶
type Filter ¶
type Filter func([]*registry.MicroServiceInstance) []*registry.MicroServiceInstance
Filter is used to filter a service during the selection process
func FilterEndpoint ¶
FilterEndpoint is an endpoint based Select Filter which will only return services with the endpoint specified.
func FilterProtocol ¶
FilterProtocol is for filtering the instances based on protocol
type Next ¶
type Next func() (*registry.MicroServiceInstance, error)
Next is a function that returns the next node based on the selector's strategy
func Random ¶
func Random(instances []*registry.MicroServiceInstance, metadata interface{}) Next
Random is a random strategy algorithm for node selection
func RoundRobin ¶
func RoundRobin(instances []*registry.MicroServiceInstance, metadata interface{}) Next
RoundRobin is a roundrobin strategy algorithm for node selection
type Option ¶
type Option func(*Options)
Option used to initialise Options struct
func SetStrategy ¶
SetStrategy sets the default strategy that selector used
type Options ¶
type Options struct { Registry registry.Registry Strategy Strategy // Other options can be stored in a context Context context.Context }
Options is having registry, strategy, context variables
type SelectOption ¶
type SelectOption func(*SelectOptions)
SelectOption used to initialise SelectOptions struct
func WithAppID ¶
func WithAppID(a string) SelectOption
WithAppID adds a application id to the function
func WithConsumerID ¶
func WithConsumerID(id string) SelectOption
WithConsumerID consumer id is added to the selectoptions
func WithFilter ¶
func WithFilter(fns []Filter) SelectOption
WithFilter adds a filter func to the list of filters
func WithMetadata ¶
func WithMetadata(a interface{}) SelectOption
WithMetadata sets the selector metadata
func WithStrategy ¶
func WithStrategy(fn Strategy) SelectOption
WithStrategy sets the selector strategy
type SelectOptions ¶
type SelectOptions struct { Filters []Filter Strategy Strategy AppID string Metadata interface{} ConsumerID string // Other options can be stored in a context Context context.Context }
SelectOptions is having micro-service filters, strategy, appid, consumerid, context
type Selector ¶
type Selector interface { Init(opts ...Option) error Options() Options // Select returns a function which should return the next node Select(microserviceName, version string, opts ...SelectOption) (Next, error) // Name of the selector String() string }
Selector builds on the registry as a mechanism to pick nodes and mark their status. This allows host pools and other things to be built using various algorithms.
type Strategy ¶
type Strategy func([]*registry.MicroServiceInstance, interface{}) Next
Strategy is a selection strategy e.g random, round robin