preferencebalancer

package module
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: May 29, 2026 License: BSD-2-Clause Imports: 16 Imported by: 0

README

Go Reference

a gRPC-Go balancer that strictly prefers some servers over others. If multiple preferred servers are available, they are used in round robin. If no preferred server is available, the rest are used in round robin.

Make sure to import this package, for example with:

import _ "github.com/Jille/grpc-preference-balancer"

This balancer can be used with a service config like:

{
	"loadBalancingPolicy": "preference_balancer",
	"loadBalancingConfig": [
		{"preference_balancer": {
			"preferredEndpoints": ["127.0.0.1:1234"]}
		}
	]
}

A service config can for example be given with google.golang.org/grpc.WithDefaultServiceConfig (and enforced with grpc.WithDisableServiceConfig to ignore the resolvers ServiceConfig).

Documentation

Overview

Package preferencebalancer registers a gRPC balancer that strictly prefers some servers over others. If multiple preferred servers are available, they are used in round robin. If no preferred server is available, the rest are used in round robin.

Make sure to import this package, for example with:

import _ "github.com/Jille/grpc-preference-balancer"

This balancer can be used with a service config like:

{"loadBalancingPolicy": "preference_balancer", "loadBalancingConfig": [{"preference_balancer": {"preferredEndpoints": ["127.0.0.1:1234"]}}]}

A service config can for example be given with google.golang.org/grpc.WithDefaultServiceConfig (and enforced with google.golang.org/grpc.WithDisableServiceConfig to ignore the resolvers ServiceConfig).

Index

Constants

View Source
const Name = "preference_balancer"

Variables

This section is empty.

Functions

func SimpleServiceConfig

func SimpleServiceConfig(preferredEndpoints []string) (string, error)

SimpleServiceConfig is an optional helper function to write a service config for you.

Types

type LBConfig

type LBConfig struct {
	serviceconfig.LoadBalancingConfig `json:"-"`

	PreferredEndpoints []string `json:"preferredEndpoints,omitempty"`
}

LBConfig is the balancer config for the preference balancer.

Jump to

Keyboard shortcuts

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