Documentation ¶
Index ¶
- Constants
- Variables
- func DoRegister() error
- func Enable() (err error)
- func GetProtocolList(m map[string]string) []string
- func GetProtocolMap(eps []string) (map[string]string, string)
- func HealthCheck(service, version, appID string, instance *MicroServiceInstance) error
- func InstallContractDiscovery(name string, f func(opts Options) ContractDiscovery)
- func InstallRegistrator(name string, f func(opts Options) Registrator)
- func InstallServiceDiscovery(name string, f func(opts Options) ServiceDiscovery)
- func MakeEndpointMap(m map[string]model.Protocol) map[string]string
- func MakeEndpoints(m map[string]model.Protocol) []string
- func Microservice2ServiceKeyStr(m *MicroService) string
- func RefreshCache(service string, ups []*MicroServiceInstance, downs map[string]struct{})
- func RegisterMicroservice() error
- func RegisterMicroserviceInstances() error
- func SetIPIndex(ip string, si *SourceInfo)
- func SetNoIndexCache()
- func URIs2Hosts(uris []string) ([]string, string, error)
- type CacheIndex
- type ContractDiscovery
- type DataCenterInfo
- type Definition
- type Framework
- type HealthChecker
- type HeartbeatService
- func (s *HeartbeatService) AddTask(microServiceID, microServiceInstanceID string)
- func (s *HeartbeatService) DoHeartBeat(microServiceID, microServiceInstanceID string)
- func (s *HeartbeatService) ReRegisterSelfMSandMSI() error
- func (s *HeartbeatService) RefreshTask(microServiceID, microServiceInstanceID string)
- func (s *HeartbeatService) RemoveTask(microServiceID, microServiceInstanceID string)
- func (s *HeartbeatService) RetryRegister(sid, iid string) error
- func (s *HeartbeatService) Start()
- func (s *HeartbeatService) Stop()
- type HeartbeatTask
- type Index
- type Item
- type MethodInfo
- type MicroService
- type MicroServiceDependency
- type MicroServiceInstance
- type Options
- type Parameter
- type Registrator
- type Response
- type Schema
- type SchemaContent
- type SchemaContents
- type SchemaValue
- type ServiceDiscovery
- type SourceInfo
- type WrapInstance
Constants ¶
const ( DefaultRegistratorPlugin = "servicecenter" DefaultServiceDiscoveryPlugin = "servicecenter" DefaultContractDiscoveryPlugin = "servicecenter" Name = "registry" SDTag = "serviceDiscovery" CDTag = "contractDiscovery" RTag = "registrator" Auto = "auto" Manual = "manual" )
constant values for registry parameters
const (
//DefaultExpireTime default expiry time is kept as 0
DefaultExpireTime = 0
)
const DefaultRetryTime = 10 * time.Second
DefaultRetryTime default retry time
Variables ¶
var DefaultAddr = "http://127.0.0.1:30100"
DefaultAddr default address of service center
var HBService = &HeartbeatService{ instances: make(map[string]*HeartbeatTask), }
HBService variable of heartbeat service
var InstanceEndpoints map[string]string
InstanceEndpoints instance endpoints
var IsEnabled bool
IsEnabled check enable
var SchemaInterfaceIndexedCache *cache.Cache
SchemaInterfaceIndexedCache key: schema interface name value: []*microservice
var SchemaServiceIndexedCache *cache.Cache
SchemaServiceIndexedCache key: schema service name value: []*microservice
var SelfInstancesCache *cache.Cache
SelfInstancesCache key: serviceID, value: []instanceID
Functions ¶
func GetProtocolList ¶
GetProtocolList returns the protocol list
func GetProtocolMap ¶
GetProtocolMap returns the protocol map
func HealthCheck ¶
func HealthCheck(service, version, appID string, instance *MicroServiceInstance) error
HealthCheck is the function adds the instance to HealthChecker
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 ¶
MakeEndpointMap returns the endpoints map
func MakeEndpoints ¶
MakeEndpoints returns the endpoints
func Microservice2ServiceKeyStr ¶
func Microservice2ServiceKeyStr(m *MicroService) string
Microservice2ServiceKeyStr prepares a microservice key
func RefreshCache ¶
func RefreshCache(service string, ups []*MicroServiceInstance, downs map[string]struct{})
RefreshCache is the function to filter changes between new pulling instances and cache
func RegisterMicroservice ¶
func RegisterMicroservice() error
RegisterMicroservice register micro-service
func RegisterMicroserviceInstances ¶
func RegisterMicroserviceInstances() error
RegisterMicroserviceInstances register micro-service instances
func SetIPIndex ¶ added in v0.7.1
func SetIPIndex(ip string, si *SourceInfo)
SetIPIndex save ip index
func SetNoIndexCache ¶ added in v0.7.1
func SetNoIndexCache()
SetNoIndexCache reset microservie instance index to no index cache
Types ¶
type CacheIndex ¶ added in v0.7.1
type CacheIndex interface { GetIndexTags() []string SetIndexTags(tags sets.String) Get(k string, tags map[string]string) (interface{}, bool) Set(k string, x interface{}) Items() map[string]*cache.Cache Delete(k string) }
CacheIndex defines interface for cache and index used by registry
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 ¶
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 HealthChecker ¶
type HealthChecker struct {
// contains filtered or unexported fields
}
HealthChecker is the struct judges the instance health in the removing cache
func (*HealthChecker) Add ¶
func (hc *HealthChecker) Add(i *WrapInstance) error
Add is the method adds a key of the instance cache into pending chan
func (*HealthChecker) Run ¶
func (hc *HealthChecker) Run()
Run is the method initializes and starts the health check process
type HeartbeatService ¶
type HeartbeatService struct {
// contains filtered or unexported fields
}
HeartbeatService heartbeat service
func (*HeartbeatService) AddTask ¶
func (s *HeartbeatService) AddTask(microServiceID, microServiceInstanceID string)
AddTask add new micro-service instance to the heartbeat system
func (*HeartbeatService) DoHeartBeat ¶
func (s *HeartbeatService) DoHeartBeat(microServiceID, microServiceInstanceID string)
DoHeartBeat do heartbeat for each instance
func (*HeartbeatService) ReRegisterSelfMSandMSI ¶
func (s *HeartbeatService) ReRegisterSelfMSandMSI() error
ReRegisterSelfMSandMSI 重新注册微服务和实例
func (*HeartbeatService) RefreshTask ¶
func (s *HeartbeatService) RefreshTask(microServiceID, microServiceInstanceID string)
RefreshTask refresh heartbeat for micro-service instance
func (*HeartbeatService) RemoveTask ¶
func (s *HeartbeatService) RemoveTask(microServiceID, microServiceInstanceID string)
RemoveTask remove micro-service instance from the heartbeat system
func (*HeartbeatService) RetryRegister ¶
func (s *HeartbeatService) RetryRegister(sid, iid string) error
RetryRegister retrying to register micro-service, and instance
func (*HeartbeatService) Start ¶
func (s *HeartbeatService) Start()
Start start the heartbeat system
type HeartbeatTask ¶
HeartbeatTask heart beat task struct
type Index ¶ added in v0.7.1
type Index interface { Set(k string, x interface{}) Get(k string, tags map[string]string) (interface{}, bool) Delete(k string) Items() map[string]*cache.Cache //TODO: tags set to defaultTag with version and app now // it can be set according to config GetTags() []string SetTags(tags sets.String) }
Index interface provide set and get for microservice instance
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 Environment string Status string Level string Schemas []string Metadata map[string]string Framework *Framework RegisterBy string }
MicroService struct having full info about micro-service
type MicroServiceDependency ¶
type MicroServiceDependency struct { Consumer *MicroService Providers []*MicroService }
MicroServiceDependency is for to represent dependencies of micro-service
type MicroServiceInstance ¶
type MicroServiceInstance struct { InstanceID string HostName string ServiceID string DefaultProtocol string DefaultEndpoint string Status string EndpointsMap map[string]string Metadata map[string]string DataCenterInfo *DataCenterInfo }
MicroServiceInstance struct having full info about micro-service instance
func (*MicroServiceInstance) Has ¶ added in v0.7.1
func (m *MicroServiceInstance) Has(tags map[string]string) bool
Has return whether microservice has tags
func (*MicroServiceInstance) WithAppID ¶ added in v0.7.1
func (m *MicroServiceInstance) WithAppID(v string) *MicroServiceInstance
WithAppID add app tag for microservice instance
type Options ¶
type Options struct { Addrs []string EnableSSL bool Tenant string 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) AddDependencies(dep *MicroServiceDependency) 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
type Response ¶
type Response struct { Description string `yaml:"description"` Schema map[string]string `yaml:"schema"` }
Response represents schema response
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 { GetMicroServiceID(appID, microServiceName, version, env string) (string, error) GetAllMicroServices() ([]*MicroService, error) GetMicroService(microServiceID string) (*MicroService, error) GetMicroServiceInstances(consumerID, providerID string) ([]*MicroServiceInstance, 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
type SourceInfo ¶
SourceInfo represent the consumer service name and metadata. it is used in route management
func GetIPIndex ¶ added in v0.7.1
func GetIPIndex(ip string) *SourceInfo
GetIPIndex get ip corresponding source info
type WrapInstance ¶
type WrapInstance struct { AppID string ServiceName string Version string Instance *MicroServiceInstance }
WrapInstance is the struct defines an instance object with appID/serviceName/version
func (*WrapInstance) ServiceKey ¶
func (i *WrapInstance) ServiceKey() string
ServiceKey is the method returns the string type current instance's service key value
func (*WrapInstance) String ¶
func (i *WrapInstance) String() string
String is the method returns the string type current instance's key value