registry

package
v0.0.0-...-8ce2553 Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2018 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultRegistryPlugin = "servicecenter"
	Name                  = "registry"
	Auto                  = "auto"
	Manual                = "manual"
)

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

Variables

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

DefaultAddr default address of service center

View Source
var HBService = &HeartbeatService{
	instances: make(map[string]*HeartbeatTask),
}

HBService variable of heartbeat service

View Source
var IPIndexedCache *cache.Cache

IPIndexedCache key: instance ip, value: microservice

View Source
var InstanceEndpoints map[string]string

InstanceEndpoints instance endpoints

View Source
var IsEnabled bool

IsEnabled check enable

View Source
var MicroserviceInstanceCache *cache.Cache

MicroserviceInstanceCache key: ServiceName:Version:AppID, value: []instance

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

View Source
var SelfInstancesCache *cache.Cache

SelfInstancesCache key: serviceID, value: []instanceID

Functions

func DoRegister

func DoRegister() error

DoRegister for registering micro-service instances

func Enable

func Enable() error

Enable create RegistryService

func GetProtocolList

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

GetProtocolList returns the protocol list

func GetProtocolMap

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

GetProtocolMap returns the protocol map

func InstallPlugin

func InstallPlugin(name string, f func(opts ...Option) Registry)

InstallPlugin install plugin

func MakeEndpointMap

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

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 RegisterMicroservice

func RegisterMicroservice() error

RegisterMicroservice register micro-service

func RegisterMicroserviceInstances

func RegisterMicroserviceInstances() error

RegisterMicroserviceInstances register micro-service instances

Types

type CacheManager

type CacheManager struct {
	// contains filtered or unexported fields
}

CacheManager cache manager struct

type DataCenterInfo

type DataCenterInfo struct {
	Name          string
	Region        string
	AvailableZone string
}

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 Framework

type Framework struct {
	Name    string
	Version string
}

Framework struct having info about micro-service version, name

type HeartbeatService

type HeartbeatService struct {
	Client *client.RegistryClient
	// 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 string) error

RetryRegister retrying 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 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
	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
	Environment     string
	EndpointsMap    map[string]string
	Metadata        map[string]string
	DataCenterInfo  *DataCenterInfo
	Stage           string
}

MicroServiceInstance struct having full info about micro-service instance

type Option

type Option func(*Options)

Option is the function of the type *Options

func Addrs

func Addrs(addrs ...string) Option

Addrs sets the address

func Compressed

func Compressed(bo bool) Option

Compressed set the Compressed parameter

func EnableSSL

func EnableSSL(bo bool) Option

EnableSSL enable the ssl

func TLSConfig

func TLSConfig(t *tls.Config) Option

TLSConfig sets tls configurations

func Tenant

func Tenant(str string) Option

Tenant sets tenant parameter

func Timeout

func Timeout(t time.Duration) Option

Timeout sets the timeout

func Verbose

func Verbose(bo bool) Option

Verbose sets the Verbose parameter

func Version

func Version(v string) Option

Version sets the version

type Options

type Options struct {
	Addrs        []string
	EnableSSL    bool
	ConfigTenant string
	Timeout      time.Duration
	TLSConfig    *tls.Config
	// Other options can be stored in a context
	Context    context.Context
	Compressed bool
	Verbose    bool
	Version    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 Registry

type Registry 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
	GetMicroServiceID(appID, microServiceName, version string) (string, error)
	GetAllMicroServices() ([]*MicroService, error)
	GetMicroService(microServiceID string) (*MicroService, error)
	GetMicroServiceInstances(consumerID, providerID string) ([]*MicroServiceInstance, error)
	FindMicroServiceInstances(consumerID, appID, microServiceName, version string) ([]*MicroServiceInstance, 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
	String() string
	AutoSync()
	AddSchemas(microServiceID, schemaName, schemaInfo string) error
	GetMicroServicesByInterface(interfaceName string) (microservices []*MicroService)
	GetSchemaContentByInterface(interfaceName string) SchemaContent
	GetSchemaContentByServiceName(svcName, version, appID, env string) []*SchemaContent
}

Registry is the interface for developer to interact with microservice registry

var RegistryService Registry

RegistryService 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 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 SourceInfo

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

SourceInfo source info

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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