registry

package
v1.5.11 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2023 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// RegistryConnDelay connection delay
	RegistryConnDelay = 3
	// MaxWaitInterval max wait interval
	MaxWaitInterval = 3 * time.Second
)
View Source
const DefaultPageSize = 100

Variables

This section is empty.

Functions

func ToConfigurators added in v0.1.4

func ToConfigurators(urls []*common.URL, f func(url *common.URL) config_center.Configurator) []config_center.Configurator

ToConfigurators converts @urls by @f to config_center.Configurators

Types

type BaseConfigurationListener added in v0.1.4

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

nolint

func (*BaseConfigurationListener) Configurators added in v0.1.4

func (bcl *BaseConfigurationListener) Configurators() []config_center.Configurator

Configurators gets Configurator from config center

func (*BaseConfigurationListener) InitWith added in v0.1.4

InitWith will init BaseConfigurationListener by @key+@Listener+@f

func (*BaseConfigurationListener) OverrideUrl added in v0.1.4

func (bcl *BaseConfigurationListener) OverrideUrl(url *common.URL)

OverrideUrl gets existing configuration rule and overrides provider url before exporting.

func (*BaseConfigurationListener) Process added in v0.1.4

Process the notification event once there's any change happens on the config.

type BaseRegistry added in v0.1.4

type BaseRegistry struct {
	*common.URL
	// contains filtered or unexported fields
}

BaseRegistry is a common logic abstract for registry. It implement Registry interface.

func (*BaseRegistry) Destroy added in v0.1.4

func (r *BaseRegistry) Destroy()

Destroy for graceful down

func (*BaseRegistry) Done added in v0.1.4

func (r *BaseRegistry) Done() chan struct{}

Done open for outside to listen the event of registry Destroy() called.

func (*BaseRegistry) GetURL added in v0.1.4

func (r *BaseRegistry) GetURL() *common.URL

GetURL for get registry's url

func (*BaseRegistry) InitBaseRegistry added in v0.1.4

func (r *BaseRegistry) InitBaseRegistry(url *common.URL, facadeRegistry FacadeBasedRegistry) Registry

InitBaseRegistry for init some local variables and set BaseRegistry's subclass to it

func (*BaseRegistry) IsAvailable added in v0.1.4

func (r *BaseRegistry) IsAvailable() bool

IsAvailable judge to is registry not closed by chan r.done

func (*BaseRegistry) Register added in v0.1.4

func (r *BaseRegistry) Register(url *common.URL) error

Register implement interface registry to register

func (*BaseRegistry) RestartCallBack added in v0.1.4

func (r *BaseRegistry) RestartCallBack() bool

RestartCallBack for reregister when reconnect

func (*BaseRegistry) Subscribe added in v0.1.4

func (r *BaseRegistry) Subscribe(url *common.URL, notifyListener NotifyListener) error

Subscribe :subscribe from registry, event will notify by notifyListener

func (*BaseRegistry) UnRegister added in v0.1.4

func (r *BaseRegistry) UnRegister(url *common.URL) error

UnRegister implement interface registry to unregister

func (*BaseRegistry) UnSubscribe added in v0.1.4

func (r *BaseRegistry) UnSubscribe(url *common.URL, notifyListener NotifyListener) error

UnSubscribe URL

func (*BaseRegistry) WaitGroup added in v0.1.4

func (r *BaseRegistry) WaitGroup() *sync.WaitGroup

WaitGroup open for outside add the waitgroup to add some logic before registry destroyed over(graceful down)

type DefaultServiceInstance added in v0.1.4

type DefaultServiceInstance struct {
	ID              string
	ServiceName     string
	Host            string
	Port            int
	Enable          bool
	Healthy         bool
	Metadata        map[string]string
	ServiceMetadata *common.MetadataInfo
	Address         string
	GroupName       string
}

DefaultServiceInstance the default implementation of ServiceInstance or change the ServiceInstance to be struct???

func (*DefaultServiceInstance) Copy added in v0.1.4

func (d *DefaultServiceInstance) Copy(endpoint *Endpoint) ServiceInstance

Copy return a instance with different port

func (*DefaultServiceInstance) GetAddress added in v0.1.4

func (d *DefaultServiceInstance) GetAddress() string

GetAddress will return the ip:Port

func (*DefaultServiceInstance) GetEndPoints added in v0.1.4

func (d *DefaultServiceInstance) GetEndPoints() []*Endpoint

GetEndPoints get end points from metadata

func (*DefaultServiceInstance) GetHost added in v0.1.4

func (d *DefaultServiceInstance) GetHost() string

GetHost will return the hostname

func (*DefaultServiceInstance) GetID added in v0.1.4

func (d *DefaultServiceInstance) GetID() string

GetID will return this instance's id. It should be unique.

func (*DefaultServiceInstance) GetMetadata added in v0.1.4

func (d *DefaultServiceInstance) GetMetadata() map[string]string

GetMetadata will return the metadata, it will never return nil

func (*DefaultServiceInstance) GetPort added in v0.1.4

func (d *DefaultServiceInstance) GetPort() int

GetPort will return the port.

func (*DefaultServiceInstance) GetServiceName added in v0.1.4

func (d *DefaultServiceInstance) GetServiceName() string

GetServiceName will return the serviceName

func (*DefaultServiceInstance) IsEnable added in v0.1.4

func (d *DefaultServiceInstance) IsEnable() bool

IsEnable will return the enable status of this instance

func (*DefaultServiceInstance) IsHealthy added in v0.1.4

func (d *DefaultServiceInstance) IsHealthy() bool

IsHealthy will return the value represent the instance whether healthy or not

func (*DefaultServiceInstance) SetServiceMetadata added in v0.1.4

func (d *DefaultServiceInstance) SetServiceMetadata(m *common.MetadataInfo)

SetServiceMetadata save metadata in instance

func (*DefaultServiceInstance) ToURLs added in v0.1.4

func (d *DefaultServiceInstance) ToURLs() []*common.URL

ToURLs

type Endpoint added in v0.1.4

type Endpoint struct {
	Port     int    `json:"port,omitempty"`
	Protocol string `json:"protocol,omitempty"`
}

nolint

type FacadeBasedRegistry added in v0.1.4

type FacadeBasedRegistry interface {
	Registry

	// CreatePath create the path in the registry
	CreatePath(string) error
	// DoRegister actually do the register job
	DoRegister(string, string) error
	// DoUnregister do the unregister job
	DoUnregister(string, string) error
	// DoSubscribe actually subscribe the URL
	DoSubscribe(conf *common.URL) (Listener, error)
	// DoUnsubscribe does unsubscribe the URL
	DoUnsubscribe(conf *common.URL) (Listener, error)
	// CloseAndNilClient close the client and then reset the client in registry to nil
	// you should notice that this method will be invoked inside a lock.
	// So you should implement this method as light weighted as you can.
	CloseAndNilClient()
	// CloseListener close listeners
	CloseListener()
	// InitListeners init listeners
	InitListeners()
}

* FacadeBasedRegistry interface is subclass of Registry, and it is designed for registry who want to inherit BaseRegistry. * You have to implement the interface to inherit BaseRegistry.

type KeyFunc added in v0.1.4

type KeyFunc func(*common.URL) string

type Listener added in v0.1.4

type Listener interface {
	// Next returns next service event once received
	Next() (*ServiceEvent, error)
	// Close closes this listener
	Close()
}

Listener Deprecated!

type MockRegistry added in v0.1.4

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

MockRegistry is used as mock registry

func (*MockRegistry) Destroy added in v0.1.4

func (r *MockRegistry) Destroy()

nolint

func (*MockRegistry) GetURL added in v0.1.4

func (r *MockRegistry) GetURL() *common.URL

nolint

func (*MockRegistry) IsAvailable added in v0.1.4

func (r *MockRegistry) IsAvailable() bool

IsAvailable is use for determine a mock registry available

func (*MockRegistry) MockEvent added in v0.1.4

func (r *MockRegistry) MockEvent(event *ServiceEvent)

nolint

func (*MockRegistry) MockEvents added in v0.1.4

func (r *MockRegistry) MockEvents(events []*ServiceEvent)

nolint

func (*MockRegistry) Register added in v0.1.4

func (*MockRegistry) Register(url *common.URL) error

Register is used as a mock registry

func (*MockRegistry) Subscribe added in v0.1.4

func (r *MockRegistry) Subscribe(url *common.URL, notifyListener NotifyListener) error

nolint

func (*MockRegistry) UnRegister added in v0.1.4

func (r *MockRegistry) UnRegister(conf *common.URL) error

nolint

func (*MockRegistry) UnSubscribe added in v0.1.4

func (r *MockRegistry) UnSubscribe(url *common.URL, notifyListener NotifyListener) error

UnSubscribe :

type NotifyListener added in v0.1.4

type NotifyListener interface {
	// Notify supports notifications on the service interface and the dimension of the data type. When a list of
	// events are passed in, it's considered as a complete list, on the other side, if one single event is
	// passed in, then it's a incremental event. Pls. note when a list (instead of single event) comes,
	// the impl of NotifyListener may abandon the accumulated result from previous notifications.
	Notify(*ServiceEvent)
	// NotifyAll the events are complete Service Event List.
	// The argument of events []*ServiceEvent is equal to urls []*URL, The Action of serviceEvent should be EventTypeUpdate.
	// If your registry center can only get all urls but can't get individual event, you should use this one.
	// After notify the address, the callback func will be invoked.
	NotifyAll([]*ServiceEvent, func())
}

nolint

type Registry

type Registry interface {
	common.Node

	// Register is used for service provider calling, register services
	// to registry. And it is also used for service consumer calling, register
	// services cared about, for dubbo's admin monitoring.
	Register(url *common.URL) error

	// UnRegister is required to support the contract:
	// 1. If it is the persistent stored data of dynamic=false, the
	//    registration data can not be found, then the IllegalStateException
	//    is thrown, otherwise it is ignored.
	// 2. Unregister according to the full url match.
	// url Registration information, is not allowed to be empty, e.g:
	// dubbo://10.20.153.10/org.apache.dubbo.foo.BarService?version=1.0.0&application=kylin
	UnRegister(url *common.URL) error

	// Subscribe is required to support the contract:
	// When creating new registry extension, pls select one of the
	// following modes.
	// Will remove in dubbogo version v1.1.0
	// mode1: return Listener with Next function which can return
	//        subscribe service event from registry
	// Deprecated!
	// subscribe(event.URL) (Listener, error)
	// Will replace mode1 in dubbogo version v1.1.0
	// mode2: callback mode, subscribe with notify(notify listener).
	Subscribe(*common.URL, NotifyListener) error

	// UnSubscribe is required to support the contract:
	// 1. If don't subscribe, ignore it directly.
	// 2. Unsubscribe by full URL match.
	// url Subscription condition, not allowed to be empty, e.g.
	// consumer://10.20.153.10/org.apache.dubbo.foo.BarService?version=1.0.0&application=kylin
	// listener A listener of the change event, not allowed to be empty
	UnSubscribe(*common.URL, NotifyListener) error
}
  • -----------------------------------NOTICE---------------------------------------------
  • If there is no special case, you'd better inherit BaseRegistry and implement the
  • FacadeBasedRegistry interface instead of directly implementing the Registry interface.
  • --------------------------------------------------------------------------------------

Registry Extension - Registry

func NewMockRegistry added in v0.1.4

func NewMockRegistry(url *common.URL) (Registry, error)

NewMockRegistry creates a mock registry

type RegistryFactory added in v0.1.4

type RegistryFactory interface {
	// GetRegistries get registries
	GetRegistries() []Registry
}

RegistryFactory

type ServiceDiscovery added in v0.1.4

type ServiceDiscovery interface {
	fmt.Stringer

	// Destroy will destroy the service discovery.
	// If the discovery cannot be destroy, it will return an error.
	Destroy() error

	// Register will register an instance of ServiceInstance to registry
	Register(instance ServiceInstance) error

	// Update will update the data of the instance in registry
	Update(instance ServiceInstance) error

	// Unregister will unregister this instance from registry
	Unregister(instance ServiceInstance) error

	// ----------------- discovery -------------------
	// GetDefaultPageSize will return the default page size
	GetDefaultPageSize() int

	// GetServices will return the all service names.
	GetServices() *gxset.HashSet

	// GetInstances will return all service instances with serviceName
	GetInstances(serviceName string) []ServiceInstance

	// GetInstancesByPage will return a page containing instances of ServiceInstance with the serviceName
	// the page will start at offset
	GetInstancesByPage(serviceName string, offset int, pageSize int) gxpage.Pager

	// GetHealthyInstancesByPage will return a page containing instances of ServiceInstance.
	// The param healthy indices that the instance should be healthy or not.
	// The page will start at offset
	GetHealthyInstancesByPage(serviceName string, offset int, pageSize int, healthy bool) gxpage.Pager

	// Batch get all instances by the specified service names
	GetRequestInstances(serviceNames []string, offset int, requestedSize int) map[string]gxpage.Pager

	// ----------------- event ----------------------
	// AddListener adds a new ServiceInstancesChangedListenerImpl
	// see addServiceInstancesChangedListener in Java
	AddListener(listener ServiceInstancesChangedListener) error
}

ServiceDiscovery is the common operations of Service Discovery

type ServiceDiscoveryHolder added in v0.1.4

type ServiceDiscoveryHolder interface {
	// GetServiceDiscovery get service discovery
	GetServiceDiscovery() ServiceDiscovery
}

ServiceDiscoveryHolder we can get a service discovery it always be a service discovery registry

type ServiceEvent added in v0.1.4

type ServiceEvent struct {
	Action  remoting.EventType
	Service *common.URL

	KeyFunc KeyFunc
	// contains filtered or unexported fields
}

ServiceEvent includes create, update, delete event

func (*ServiceEvent) Key added in v0.1.4

func (e *ServiceEvent) Key() string

Key() generate the key for service.Key(). It is cached once.

func (*ServiceEvent) String added in v0.1.4

func (e *ServiceEvent) String() string

String return the description of event

func (*ServiceEvent) Update added in v0.1.4

func (e *ServiceEvent) Update(url *common.URL)

Update() update the url with the merged URL. Work with Updated() can reduce the process of some merging URL.

func (*ServiceEvent) Updated added in v0.1.4

func (e *ServiceEvent) Updated() bool

Updated() check if the url is updated. If the serviceEvent is updated, then it don't need merge url again.

type ServiceInstance added in v0.1.4

type ServiceInstance interface {

	// GetID will return this instance's id. It should be unique.
	GetID() string

	// GetServiceName will return the serviceName
	GetServiceName() string

	// GetHost will return the hostname
	GetHost() string

	// GetPort will return the port.
	GetPort() int

	// IsEnable will return the enable status of this instance
	IsEnable() bool

	// IsHealthy will return the value represent the instance whether healthy or not
	IsHealthy() bool

	// GetMetadata will return the metadata
	GetMetadata() map[string]string

	// ToURLs
	ToURLs() []*common.URL

	// GetEndPoints
	GetEndPoints() []*Endpoint

	// Copy
	Copy(endpoint *Endpoint) ServiceInstance

	// GetAddress
	GetAddress() string

	// SetServiceMetadata
	SetServiceMetadata(info *common.MetadataInfo)
}

ServiceInstance is the model class of an instance of a service, which is used for service registration and discovery.

type ServiceInstanceCustomizer added in v0.1.4

type ServiceInstanceCustomizer interface {
	gxsort.Prioritizer

	Customize(instance ServiceInstance)
}

ServiceInstanceCustomizer is an extension point which allow user using custom logic to modify instance Be careful of priority. Usually you should use number between [100, 9000] other number will be thought as system reserve number

type ServiceInstancesChangedEvent added in v0.1.4

type ServiceInstancesChangedEvent struct {
	observer.BaseEvent
	ServiceName string
	Instances   []ServiceInstance
}

ServiceInstancesChangedEvent represents service instances make some changing

func NewServiceInstancesChangedEvent added in v0.1.4

func NewServiceInstancesChangedEvent(serviceName string, instances []ServiceInstance) *ServiceInstancesChangedEvent

NewServiceInstancesChangedEvent will create the ServiceInstanceChangedEvent instance

func (*ServiceInstancesChangedEvent) String added in v0.1.4

String return the description of the event

type ServiceInstancesChangedListener added in v0.1.4

type ServiceInstancesChangedListener interface {
	// OnEvent on ServiceInstancesChangedEvent the service instances change event
	OnEvent(e observer.Event) error
	// AddListenerAndNotify add notify listener and notify to listen service event
	AddListenerAndNotify(serviceKey string, notify NotifyListener)
	// RemoveListener remove notify listener
	RemoveListener(serviceKey string)
	// GetServiceNames return all listener service names
	GetServiceNames() *gxset.HashSet
	// Accept return true if the name is the same
	Accept(e observer.Event) bool
	// GetEventType returns ServiceInstancesChangedEvent
	GetEventType() reflect.Type
	// GetPriority returns -1, it will be the first invoked listener
	GetPriority() int
}

ServiceInstancesChangedListener The Service Discovery Changed Event Listener

Jump to

Keyboard shortcuts

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