registry

package
v2.7.1 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2022 License: Apache-2.0 Imports: 24 Imported by: 14

Documentation

Index

Constants

View Source
const (
	DefaultRegistratorPlugin       = "servicecenter"
	DefaultServiceDiscoveryPlugin  = "servicecenter"
	DefaultContractDiscoveryPlugin = "servicecenter"
	Name                           = "registry"
	SDTag                          = "serviceDiscovery"
	CDTag                          = "contractDiscovery"
	RTag                           = "registrator"
	Auto                           = "auto"
	Manual                         = "manual"
	PersistenceHeartBeat           = "ping-pong"
	NonPersistenceHeartBeat        = "non-keep-alive"
	DefaultInterval                = 30 * time.Second
	MinInterval                    = 10 * time.Second
)

constant values for registry parameters

View Source
const (
	//DefaultExpireTime default expiry time is kept as 0
	DefaultExpireTime = 0
)
View Source
const DefaultRetryTime = 10 * time.Second

DefaultRetryTime default retry time

View Source
const (
	SSLEnabledQuery = "sslEnabled=true"
)

const

Variables

View Source
var DefaultAddr = "http://127.0.0.1:30100"

DefaultAddr default address of service center

View Source
var HBService = &HeartbeatService{}

HBService variable of heartbeat service

View Source
var InstanceEndpoints = make(map[string]string)

InstanceEndpoints instance endpoints

View Source
var IsEnabled bool

IsEnabled check enable

View Source
var ProvidersMicroServiceCache *cache.Cache

ProvidersMicroServiceCache key: micro service name and appId, value: []*MicroService

View Source
var SchemaInterfaceIndexedCache *cache.Cache

SchemaInterfaceIndexedCache key: schema interface name value: []*microservice

View Source
var SchemaServiceIndexedCache *cache.Cache

SchemaServiceIndexedCache key: schema service name value: []*microservice

Functions

func AddProviderToCache

func AddProviderToCache(serverName, appID string)

AddProviderToCache refresh provider simpleCache

func DoRegister

func DoRegister() error

DoRegister for registering micro-service instances

func Enable

func Enable() (err error)

Enable create DefaultRegistrator

func EnableRegistryCache

func EnableRegistryCache()

EnableRegistryCache init caches

func FillUnspecifiedIP

func FillUnspecifiedIP(host string) (string, error)

FillUnspecifiedIP replace 0.0.0.0 or :: IPv4 and IPv6 unspecified IP address with local NIC IP.

func GetDuration added in v2.3.0

func GetDuration(key string, def time.Duration) time.Duration

GetDuration return the time.Duration type value by specified key

func GetIndexedCacheKey

func GetIndexedCacheKey(service string, tags map[string]string) (ss string)

GetIndexedCacheKey combine keys in order, use sets to return sorted list

func GetProtocolList

func GetProtocolList(m map[string]*Endpoint) []string

GetProtocolList returns the protocol list

func GetProtocolMap

func GetProtocolMap(eps []string) (map[string]*Endpoint, string)

GetProtocolMap returns the protocol map

func InstallContractDiscovery

func InstallContractDiscovery(name string, f func(opts Options) ContractDiscovery)

InstallContractDiscovery install contract service client

func InstallRegistrator

func InstallRegistrator(name string, f func(opts Options) Registrator)

InstallRegistrator install registrator plugin

func InstallServiceDiscovery

func InstallServiceDiscovery(name string, f func(opts Options) ServiceDiscovery)

InstallServiceDiscovery install service discovery client

func MakeEndpointMap

func MakeEndpointMap(m map[string]model.Protocol) (map[string]*Endpoint, error)

MakeEndpointMap returns the endpoints map

func MakeEndpoints

func MakeEndpoints(m map[string]model.Protocol) []string

MakeEndpoints returns the endpoints

func Microservice2ServiceKeyStr

func Microservice2ServiceKeyStr(m *MicroService) string

Microservice2ServiceKeyStr prepares a microservice key

func RegisterService

func RegisterService() error

RegisterService register micro-service

func RegisterServiceInstances

func RegisterServiceInstances() error

RegisterServiceInstances register micro-service instances

func SetIPIndex

func SetIPIndex(ip string, si *SourceInfo)

SetIPIndex save ip index

func URIs2Hosts

func URIs2Hosts(uris []string) ([]string, string, error)

URIs2Hosts return hosts and scheme

Types

type CacheIndex

type CacheIndex interface {
	Get(service string, tags map[string]string) ([]*MicroServiceInstance, bool)
	//Set will overwrite all instances correspond to a service name
	Set(service string, instances []*MicroServiceInstance)
	FullCache() *cache.Cache
	Delete(service string)
}

CacheIndex is a unified local instances cache manager

var MicroserviceInstanceIndex CacheIndex

MicroserviceInstanceIndex key: ServiceName, value: []instance

type ContractDiscovery

type ContractDiscovery interface {
	GetMicroServicesByInterface(interfaceName string) (microservices []*MicroService)
	GetSchemaContentByInterface(interfaceName string) SchemaContent
	GetSchemaContentByServiceName(svcName, version, appID, env string) []*SchemaContent
	Close() error
}

ContractDiscovery fetch schema content from remote or local

var DefaultContractDiscoveryService ContractDiscovery

DefaultContractDiscoveryService supplies contract discovery

type DataCenterInfo

type DataCenterInfo struct {
	Name          string `json:"name"`
	Region        string `json:"region"`
	AvailableZone string `json:"availableZone"`
}

DataCenterInfo represents micro-service data center info

type Definition

type Definition struct {
	Types      string                 `yaml:"type"`
	XJavaClass string                 `yaml:"x-java-class"`
	Properties map[string]interface{} `yaml:"properties"`
}

Definition struct represents types, xjavaclass, properities

type Endpoint

type Endpoint struct {
	SSLEnabled bool   `json:"sslEnabled"`
	Address    string `json:"address"`
}

Endpoint struct having full info about micro-service instance endpoint

func NewEndPoint

func NewEndPoint(schema string) (*Endpoint, error)

NewEndPoint return a Endpoint object what parse from url

func (*Endpoint) GenEndpoint

func (e *Endpoint) GenEndpoint() string

GenEndpoint return the endpoint string which it contain the sslEnabled=true query arg or not

func (*Endpoint) IsSSLEnable

func (e *Endpoint) IsSSLEnable() bool

IsSSLEnable return it is use ssl or not

func (*Endpoint) SetSSLEnable

func (e *Endpoint) SetSSLEnable(enabled bool)

SetSSLEnable set ssl enable or not

func (*Endpoint) String

func (e *Endpoint) String() string

type Framework

type Framework struct {
	Name    string
	Version string
}

Framework struct having info about micro-service version, name

type HeartbeatService

type HeartbeatService struct {
	HeartbeatMode string

	Interval time.Duration
	// contains filtered or unexported fields
}

HeartbeatService heartbeat service

func (*HeartbeatService) DoHeartBeat

func (s *HeartbeatService) DoHeartBeat(microServiceID, microServiceInstanceID string, instanceHeartbeatMode string) error

DoHeartBeat do heartbeat for each instance

func (*HeartbeatService) ReRegisterSelfMSandMSI

func (s *HeartbeatService) ReRegisterSelfMSandMSI() error

ReRegisterSelfMSandMSI 重新注册微服务和实例

func (*HeartbeatService) RetryRegister

func (s *HeartbeatService) RetryRegister(sid, iid string)

RetryRegister try to register micro-service, and instance

func (*HeartbeatService) Start

func (s *HeartbeatService) Start()

Start start the heartbeat system

func (*HeartbeatService) Stop

func (s *HeartbeatService) Stop()

Stop stop the heartbeat system

type HeartbeatTask

type HeartbeatTask struct {
	ServiceID  string
	InstanceID string
	Time       time.Time
	Running    bool
}

HeartbeatTask heart beat task struct

type IndexCache

type IndexCache struct {
	CriteriaStore []map[string]string //all criteria need to be saved in here so that we can update indexedCache, during Set process
	// contains filtered or unexported fields
}

IndexCache return instances by criteria

func NewIndexCache

func NewIndexCache() *IndexCache

NewIndexCache create a cache which saves and manage instances

func (*IndexCache) Delete

func (ic *IndexCache) Delete(k string)

Delete remove one service's instances

func (*IndexCache) FullCache

func (ic *IndexCache) FullCache() *cache.Cache

FullCache return all instances

func (*IndexCache) Get

func (ic *IndexCache) Get(k string, tags map[string]string) ([]*MicroServiceInstance, bool)

Get return instances cache by criteria

func (*IndexCache) Set

func (ic *IndexCache) Set(k string, instances []*MicroServiceInstance)

Set overwrite instances cache

type Item

type Item struct {
	Type string                 `yaml:"type"`
	XML  map[string]interface{} `yaml:"xml"`
}

Item represents type of the schema

type MethodInfo

type MethodInfo struct {
	OperationID string              `yaml:"operationId"`
	Parameters  []Parameter         `yaml:"parameters"`
	Response    map[string]Response `yaml:"responses"`
}

MethodInfo represents method info

type MicroService

type MicroService struct {
	ServiceID   string
	AppID       string
	ServiceName string
	Version     string
	Paths       []ServicePath
	Environment string
	Status      string
	Level       string
	Schemas     []string
	Metadata    map[string]string
	Framework   *Framework
	RegisterBy  string
	Alias       string
}

MicroService struct having full info about micro-service

func GetProvidersFromCache

func GetProvidersFromCache() []*MicroService

GetProvidersFromCache get local provider simpleCache

type MicroServiceDependency

type MicroServiceDependency struct {
	Consumer  *MicroService
	Providers []*MicroService
}

MicroServiceDependency is for to represent dependencies of micro-service

type MicroServiceInstance

type MicroServiceInstance struct {
	App             string
	ServiceName     string
	Version         string
	InstanceID      string               `json:"instanceID"`
	HostName        string               `json:"hostName"`
	ServiceID       string               `json:"serviceID"`
	DefaultProtocol string               `json:"defaultProtocol"`
	DefaultEndpoint string               `json:"defaultEndpoint"`
	Status          string               `json:"status"`
	EndpointsMap    map[string]*Endpoint `json:"endpointsMap"`
	Metadata        map[string]string    `json:"metadata"`
	DataCenterInfo  *DataCenterInfo      `json:"dataCenterInfo"`
}

MicroServiceInstance struct having full info about micro-service instance

func (*MicroServiceInstance) AppID added in v2.1.1

func (m *MicroServiceInstance) AppID() string

func (*MicroServiceInstance) Equal

Equal compares 2 instances is same or not

func (*MicroServiceInstance) GetVersion added in v2.1.1

func (m *MicroServiceInstance) GetVersion() string

func (*MicroServiceInstance) Has

func (m *MicroServiceInstance) Has(tags map[string]string) bool

Has return whether microservice has tags

func (*MicroServiceInstance) WithAppID

WithAppID add app tag for microservice instance

type Options

type Options struct {
	Addrs      []string
	EnableSSL  bool
	Timeout    time.Duration
	TLSConfig  *tls.Config
	Compressed bool
	Verbose    bool
	Version    string
	ConfigPath string
}

Options having micro-service parameters

type Parameter

type Parameter struct {
	Name      string      `yaml:"name"`
	In        string      `yaml:"in"`
	Required  bool        `yaml:"required"`
	Type      string      `yaml:"type"`
	Format    string      `yaml:"format"`
	Items     Item        `yaml:"items"`
	ColFormat string      `yaml:"collectionFormat"`
	Schema    SchemaValue `yaml:"schema"`
}

Parameter represents schema parameters

type Registrator

type Registrator interface {
	//Close destroy connection between the registry client and server
	Close() error
	//RegisterService register a microservice to registry, if it is duplicated in registry, it returns error
	RegisterService(microService *MicroService) (string, error)
	//RegisterServiceInstance register a microservice instance to registry
	RegisterServiceInstance(sid string, instance *MicroServiceInstance) (string, error)
	RegisterServiceAndInstance(microService *MicroService, instance *MicroServiceInstance) (string, string, error)
	Heartbeat(microServiceID, microServiceInstanceID string) (bool, error)
	WSHeartbeat(microServiceID, microServiceInstanceID string, callback func()) (bool, error)
	UnRegisterMicroServiceInstance(microServiceID, microServiceInstanceID string) error
	UpdateMicroServiceInstanceStatus(microServiceID, microServiceInstanceID, status string) error
	UpdateMicroServiceProperties(microServiceID string, properties map[string]string) error
	UpdateMicroServiceInstanceProperties(microServiceID, microServiceInstanceID string, properties map[string]string) error
	AddSchemas(microServiceID, schemaName, schemaInfo string) error
}

Registrator is the interface for developer to update information in service registry

var DefaultRegistrator Registrator

DefaultRegistrator is the client of registry, you can call the method of it to interact with microservice registry

func NewRegistrator

func NewRegistrator(name string, opts Options) (Registrator, error)

NewRegistrator return registrator

type Response

type Response struct {
	Description string            `yaml:"description"`
	Schema      map[string]string `yaml:"schema"`
}

Response represents schema response

type Schema

type Schema struct {
	Schema string `json:"schema"`
}

Schema to represents schema info

type SchemaContent

type SchemaContent struct {
	Swagger    string                           `yaml:"swagger"`
	Info       map[string]string                `yaml:"info"`
	BasePath   string                           `yaml:"basePath"`
	Produces   []string                         `yaml:"produces"`
	Paths      map[string]map[string]MethodInfo `yaml:"paths"`
	Definition map[string]Definition            `yaml:"definitions"`
}

SchemaContent represents schema contents info

type SchemaContents

type SchemaContents struct {
	Schemas []*SchemaContent
}

SchemaContents represents array of schema contents

type SchemaValue

type SchemaValue struct {
	Reference            string                 `yaml:"$ref"`
	Format               string                 `yaml:"format"`
	Title                string                 `yaml:"title"`
	Description          string                 `yaml:"description"`
	Default              string                 `yaml:"default"`
	MultipleOf           int                    `yaml:"multipleOf"`
	ExclusiveMaximum     int                    `yaml:"exclusiveMaximum"`
	Minimum              int                    `yaml:"minimum"`
	ExclusiveMinimum     int                    `yaml:"exclusiveMinimum"`
	MaxLength            int                    `yaml:"maxLength"`
	MinLength            int                    `yaml:"minLength"`
	Pattern              int                    `yaml:"pattern"`
	MaxItems             int                    `yaml:"maxItems"`
	MinItems             int                    `yaml:"minItems"`
	UniqueItems          bool                   `yaml:"uniqueItems"`
	MaxProperties        int                    `yaml:"maxProperties"`
	MinProperties        int                    `yaml:"minProperties"`
	Required             bool                   `yaml:"required"`
	Enum                 []interface{}          `yaml:"enum"`
	Type                 string                 `yaml:"type"`
	Items                Item                   `yaml:"items"`
	Properties           map[string]interface{} `yaml:"properties"`
	AdditionalProperties map[string]string      `yaml:"additionalProperties"`
}

SchemaValue represents additional info of schema

type ServiceDiscovery

type ServiceDiscovery interface {
	GetMicroService(microServiceID string) (*MicroService, error)
	FindMicroServiceInstances(consumerID, microServiceName string, tags utiltags.Tags) ([]*MicroServiceInstance, error)
	AutoSync()
	Close() error
}

ServiceDiscovery fetch service and instances from remote or local

var DefaultServiceDiscoveryService ServiceDiscovery

DefaultServiceDiscoveryService supplies service discovery

func NewDiscovery

func NewDiscovery(name string, opts Options) (ServiceDiscovery, error)

NewDiscovery create discovery service

type ServicePath

type ServicePath struct {
	Path     string
	Property map[string]string
}

ServicePath has info about service path and property

type SourceInfo

type SourceInfo struct {
	Name string
	Tags map[string]string
}

SourceInfo represent the consumer service name and metadata. it is used in route management

func GetIPIndex

func GetIPIndex(ip string) *SourceInfo

GetIPIndex get ip corresponding source info

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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