Documentation ¶
Index ¶
Constants ¶
View Source
const Lot = 10
Variables ¶
View Source
var ErrorHasBeenClosed = errors.New("has been closed")
Functions ¶
func SetBufSize ¶
Types ¶
type Discovery ¶
type Discovery interface { // GetService 返回服务名相关的服务实例 GetService(ctx context.Context, serviceName string) ([]*ServiceInstance, error) // Watch 根据服务名创建监控 Watch(ctx context.Context, serviceName string) (Watcher, error) }
Discovery 服务发现抽象
type MagicNumberGeneration ¶
type MagicNumberGeneration func() int64
MagicNumberGeneration 要保证同一个服务种子一致
type Registrar ¶
type Registrar interface { // Register 注册 Register(ctx context.Context, service *ServiceInstance) error // Deregister 注销 Deregister(ctx context.Context, service *ServiceInstance) error }
Registrar 注册抽象
type RockSteadierSubset ¶
type RockSteadierSubset struct {
// contains filtered or unexported fields
}
func NewRockSteadierSubset ¶
func NewRockSteadierSubset(ctx context.Context, clients, services []int, magicNumberGeneration MagicNumberGeneration, options ...options.Option) *RockSteadierSubset
func (*RockSteadierSubset) AddService ¶
func (r *RockSteadierSubset) AddService(ctx context.Context, ids []int) error
func (*RockSteadierSubset) Close ¶
func (r *RockSteadierSubset) Close()
func (*RockSteadierSubset) GetServices ¶
func (r *RockSteadierSubset) GetServices(client int) []int
func (*RockSteadierSubset) RemoveService ¶
func (r *RockSteadierSubset) RemoveService(ctx context.Context, ids []int) error
type ServiceInstance ¶
type ServiceInstance struct { // ID: 全局唯一ID ID string `json:"id"` // Name: 注册服务的名称 Name string `json:"name"` // Version: 版本信息 Version string `json:"version"` // Metadata: 可携带的元数据 Metadata map[string]string `json:"metadata"` // Endpoints: 服务实例的端点地址 // schema: // http://127.0.0.1:8000?isSecure=false // grpc://127.0.0.1:9000?isSecure=false Endpoints []string `json:"endpoints"` }
ServiceInstance 服务发现的实例
type Watcher ¶
type Watcher interface { Next() ([]*ServiceInstance, error) // Stop 停止监控行为 Stop() error }
Watcher 服务监控 Watch需要满足以下条件 1. 第一次 GetService 的列表不为空 2. 发现任何服务实例更改 不满足以上两种条件,Next则会无限等待直到上下文截止
Click to show internal directories.
Click to hide internal directories.