Documentation
¶
Index ¶
- Constants
- func ToConfigurators(urls []*common.URL, f func(url *common.URL) config_center.Configurator) []config_center.Configurator
- type BaseConfigurationListener
- func (bcl *BaseConfigurationListener) Configurators() []config_center.Configurator
- func (bcl *BaseConfigurationListener) InitWith(key string, listener config_center.ConfigurationListener, ...)
- func (bcl *BaseConfigurationListener) OverrideUrl(url *common.URL)
- func (bcl *BaseConfigurationListener) Process(event *config_center.ConfigChangeEvent)
- type BaseRegistry
- func (r *BaseRegistry) Destroy()
- func (r *BaseRegistry) Done() chan struct{}
- func (r *BaseRegistry) GetUrl() common.URL
- func (r *BaseRegistry) InitBaseRegistry(url *common.URL, facadeRegistry FacadeBasedRegistry) Registry
- func (r *BaseRegistry) IsAvailable() bool
- func (r *BaseRegistry) Register(conf common.URL) error
- func (r *BaseRegistry) RestartCallBack() bool
- func (r *BaseRegistry) Subscribe(url *common.URL, notifyListener NotifyListener) error
- func (r *BaseRegistry) UnRegister(conf common.URL) error
- func (r *BaseRegistry) UnSubscribe(url *common.URL, notifyListener NotifyListener) error
- func (r *BaseRegistry) WaitGroup() *sync.WaitGroup
- type DefaultServiceInstance
- func (d *DefaultServiceInstance) GetHost() string
- func (d *DefaultServiceInstance) GetId() string
- func (d *DefaultServiceInstance) GetMetadata() map[string]string
- func (d *DefaultServiceInstance) GetPort() int
- func (d *DefaultServiceInstance) GetServiceName() string
- func (d *DefaultServiceInstance) IsEnable() bool
- func (d *DefaultServiceInstance) IsHealthy() bool
- type FacadeBasedRegistry
- type Listener
- type MockRegistry
- func (r *MockRegistry) Destroy()
- func (r *MockRegistry) GetUrl() common.URL
- func (r *MockRegistry) IsAvailable() bool
- func (r *MockRegistry) MockEvent(event *ServiceEvent)
- func (*MockRegistry) Register(url common.URL) error
- func (r *MockRegistry) Subscribe(url *common.URL, notifyListener NotifyListener) error
- func (r *MockRegistry) UnRegister(conf common.URL) error
- func (r *MockRegistry) UnSubscribe(url *common.URL, notifyListener NotifyListener) error
- type NotifyListener
- type Registry
- type RegistryFactory
- type ServiceDiscovery
- type ServiceDiscoveryHolder
- type ServiceEvent
- type ServiceInstance
- type ServiceInstanceCustomizer
- type ServiceInstancesChangedEvent
- type ServiceInstancesChangedListener
Constants ¶
const ( // RegistryConnDelay connection delay RegistryConnDelay = 3 // MaxWaitInterval max wait interval MaxWaitInterval = 3 * time.Second )
const DefaultPageSize = 100
Variables ¶
This section is empty.
Functions ¶
func ToConfigurators ¶ added in v1.2.0
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 v1.2.0
type BaseConfigurationListener struct {
// contains filtered or unexported fields
}
nolint
func (*BaseConfigurationListener) Configurators ¶ added in v1.2.0
func (bcl *BaseConfigurationListener) Configurators() []config_center.Configurator
Configurators gets Configurator from config center
func (*BaseConfigurationListener) InitWith ¶ added in v1.2.0
func (bcl *BaseConfigurationListener) InitWith(key string, listener config_center.ConfigurationListener, f func(url *common.URL) config_center.Configurator)
InitWith will init BaseConfigurationListener by @key+@Listener+@f
func (*BaseConfigurationListener) OverrideUrl ¶ added in v1.2.0
func (bcl *BaseConfigurationListener) OverrideUrl(url *common.URL)
OverrideUrl gets existing configuration rule and overrides provider url before exporting.
func (*BaseConfigurationListener) Process ¶ added in v1.2.0
func (bcl *BaseConfigurationListener) Process(event *config_center.ConfigChangeEvent)
Process the notification event once there's any change happens on the config.
type BaseRegistry ¶ added in v1.3.0
BaseRegistry is a common logic abstract for registry. It implement Registry interface.
func (*BaseRegistry) Destroy ¶ added in v1.3.0
func (r *BaseRegistry) Destroy()
Destroy for graceful down
func (*BaseRegistry) Done ¶ added in v1.3.0
func (r *BaseRegistry) Done() chan struct{}
Done open for outside to listen the event of registry Destroy() called.
func (*BaseRegistry) GetUrl ¶ added in v1.3.0
func (r *BaseRegistry) GetUrl() common.URL
GetUrl for get registry's url
func (*BaseRegistry) InitBaseRegistry ¶ added in v1.3.0
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 v1.3.0
func (r *BaseRegistry) IsAvailable() bool
IsAvailable judge to is registry not closed by chan r.done
func (*BaseRegistry) Register ¶ added in v1.3.0
func (r *BaseRegistry) Register(conf common.URL) error
Register implement interface registry to register
func (*BaseRegistry) RestartCallBack ¶ added in v1.3.0
func (r *BaseRegistry) RestartCallBack() bool
RestartCallBack for reregister when reconnect
func (*BaseRegistry) Subscribe ¶ added in v1.3.0
func (r *BaseRegistry) Subscribe(url *common.URL, notifyListener NotifyListener) error
Subscribe :subscribe from registry, event will notify by notifyListener
func (*BaseRegistry) UnRegister ¶ added in v1.5.0
func (r *BaseRegistry) UnRegister(conf common.URL) error
UnRegister implement interface registry to unregister
func (*BaseRegistry) UnSubscribe ¶ added in v1.5.0
func (r *BaseRegistry) UnSubscribe(url *common.URL, notifyListener NotifyListener) error
UnSubscribe URL
func (*BaseRegistry) WaitGroup ¶ added in v1.3.0
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 v1.5.0
type DefaultServiceInstance struct {
Id string
ServiceName string
Host string
Port int
Enable bool
Healthy bool
Metadata map[string]string
}
DefaultServiceInstance the default implementation of ServiceInstance or change the ServiceInstance to be struct???
func (*DefaultServiceInstance) GetHost ¶ added in v1.5.0
func (d *DefaultServiceInstance) GetHost() string
GetHost will return the hostname
func (*DefaultServiceInstance) GetId ¶ added in v1.5.0
func (d *DefaultServiceInstance) GetId() string
GetId will return this instance's id. It should be unique.
func (*DefaultServiceInstance) GetMetadata ¶ added in v1.5.0
func (d *DefaultServiceInstance) GetMetadata() map[string]string
GetMetadata will return the metadata, it will never return nil
func (*DefaultServiceInstance) GetPort ¶ added in v1.5.0
func (d *DefaultServiceInstance) GetPort() int
GetPort will return the port.
func (*DefaultServiceInstance) GetServiceName ¶ added in v1.5.0
func (d *DefaultServiceInstance) GetServiceName() string
GetServiceName will return the serviceName
func (*DefaultServiceInstance) IsEnable ¶ added in v1.5.0
func (d *DefaultServiceInstance) IsEnable() bool
IsEnable will return the enable status of this instance
func (*DefaultServiceInstance) IsHealthy ¶ added in v1.5.0
func (d *DefaultServiceInstance) IsHealthy() bool
IsHealthy will return the value represent the instance whether healthy or not
type FacadeBasedRegistry ¶ added in v1.3.0
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 Listener ¶ added in v1.1.0
type Listener interface {
// Next returns next service event once received
Next() (*ServiceEvent, error)
// Close closes this listener
Close()
}
Listener Deprecated!
type MockRegistry ¶ added in v1.1.0
type MockRegistry struct {
// contains filtered or unexported fields
}
MockRegistry is used as mock registry
func (*MockRegistry) IsAvailable ¶ added in v1.1.0
func (r *MockRegistry) IsAvailable() bool
IsAvailable is use for determine a mock registry available
func (*MockRegistry) MockEvent ¶ added in v1.1.0
func (r *MockRegistry) MockEvent(event *ServiceEvent)
nolint
func (*MockRegistry) Register ¶ added in v1.1.0
func (*MockRegistry) Register(url common.URL) error
Register is used as a mock registry
func (*MockRegistry) Subscribe ¶ added in v1.1.0
func (r *MockRegistry) Subscribe(url *common.URL, notifyListener NotifyListener) error
nolint
func (*MockRegistry) UnRegister ¶ added in v1.5.0
func (r *MockRegistry) UnRegister(conf common.URL) error
nolint
func (*MockRegistry) UnSubscribe ¶ added in v1.5.0
func (r *MockRegistry) UnSubscribe(url *common.URL, notifyListener NotifyListener) error
UnSubscribe :
type NotifyListener ¶ added in v1.2.0
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)
}
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
type RegistryFactory ¶ added in v1.5.1
type RegistryFactory interface {
// GetRegistries get registries
GetRegistries() []Registry
}
RegistryFactory
type ServiceDiscovery ¶ added in v1.5.0
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 ServiceInstancesChangedListener
// see addServiceInstancesChangedListener in Java
AddListener(listener *ServiceInstancesChangedListener) error
// DispatchEventByServiceName dispatches the ServiceInstancesChangedEvent to service instance whose name is serviceName
DispatchEventByServiceName(serviceName string) error
// DispatchEventForInstances dispatches the ServiceInstancesChangedEvent to target instances
DispatchEventForInstances(serviceName string, instances []ServiceInstance) error
// DispatchEvent dispatches the event
DispatchEvent(event *ServiceInstancesChangedEvent) error
}
ServiceDiscovery is the common operations of Service Discovery
type ServiceDiscoveryHolder ¶ added in v1.5.1
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 v1.1.0
ServiceEvent includes create, update, delete event
func (ServiceEvent) String ¶ added in v1.1.0
func (e ServiceEvent) String() string
String return the description of event
type ServiceInstance ¶ added in v1.5.0
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
}
ServiceInstance is the model class of an instance of a service, which is used for service registration and discovery.
type ServiceInstanceCustomizer ¶ added in v1.5.0
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 v1.5.0
type ServiceInstancesChangedEvent struct {
observer.BaseEvent
ServiceName string
Instances []ServiceInstance
}
ServiceInstancesChangedEvent represents service instances make some changing
func NewServiceInstancesChangedEvent ¶ added in v1.5.0
func NewServiceInstancesChangedEvent(serviceName string, instances []ServiceInstance) *ServiceInstancesChangedEvent
NewServiceInstancesChangedEvent will create the ServiceInstanceChangedEvent instance
func (*ServiceInstancesChangedEvent) String ¶ added in v1.5.0
func (s *ServiceInstancesChangedEvent) String() string
String return the description of the event
type ServiceInstancesChangedListener ¶ added in v1.5.0
type ServiceInstancesChangedListener struct {
ServiceName string
ChangedNotify observer.ChangedNotify
}
The Service Discovery Changed Event Listener
func (*ServiceInstancesChangedListener) Accept ¶ added in v1.5.0
func (lstn *ServiceInstancesChangedListener) Accept(e observer.Event) bool
Accept return true if the name is the same
func (*ServiceInstancesChangedListener) GetEventType ¶ added in v1.5.0
func (lstn *ServiceInstancesChangedListener) GetEventType() reflect.Type
GetEventType returns ServiceInstancesChangedEvent
func (*ServiceInstancesChangedListener) GetPriority ¶ added in v1.5.0
func (lstn *ServiceInstancesChangedListener) GetPriority() int
GetPriority returns -1, it will be the first invoked listener