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) Copy(endpoint *Endpoint) ServiceInstance
- func (d *DefaultServiceInstance) GetAddress() string
- func (d *DefaultServiceInstance) GetEndPoints() []*Endpoint
- 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
- func (d *DefaultServiceInstance) SetServiceMetadata(m *common.MetadataInfo)
- func (d *DefaultServiceInstance) ToURLs() []*common.URL
- type Endpoint
- 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 (r *MockRegistry) MockEvents(events []*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 ¶
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 ¶
type BaseConfigurationListener struct {
// contains filtered or unexported fields
}
nolint
func (*BaseConfigurationListener) Configurators ¶
func (bcl *BaseConfigurationListener) Configurators() []config_center.Configurator
Configurators gets Configurator from config center
func (*BaseConfigurationListener) InitWith ¶
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 ¶
func (bcl *BaseConfigurationListener) OverrideUrl(url *common.URL)
OverrideUrl gets existing configuration rule and overrides provider url before exporting.
func (*BaseConfigurationListener) Process ¶
func (bcl *BaseConfigurationListener) Process(event *config_center.ConfigChangeEvent)
Process the notification event once there's any change happens on the config.
type BaseRegistry ¶
BaseRegistry is a common logic abstract for registry. It implement Registry interface.
func (*BaseRegistry) Done ¶
func (r *BaseRegistry) Done() chan struct{}
Done open for outside to listen the event of registry Destroy() called.
func (*BaseRegistry) GetURL ¶
func (r *BaseRegistry) GetURL() *common.URL
GetURL for get registry's url
func (*BaseRegistry) InitBaseRegistry ¶
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 ¶
func (r *BaseRegistry) IsAvailable() bool
IsAvailable judge to is registry not closed by chan r.done
func (*BaseRegistry) Register ¶
func (r *BaseRegistry) Register(conf *common.URL) error
Register implement interface registry to register
func (*BaseRegistry) RestartCallBack ¶
func (r *BaseRegistry) RestartCallBack() bool
RestartCallBack for reregister when reconnect
func (*BaseRegistry) Subscribe ¶
func (r *BaseRegistry) Subscribe(url *common.URL, notifyListener NotifyListener) error
Subscribe :subscribe from registry, event will notify by notifyListener
func (*BaseRegistry) UnRegister ¶
func (r *BaseRegistry) UnRegister(conf *common.URL) error
UnRegister implement interface registry to unregister
func (*BaseRegistry) UnSubscribe ¶
func (r *BaseRegistry) UnSubscribe(url *common.URL, notifyListener NotifyListener) error
UnSubscribe URL
func (*BaseRegistry) WaitGroup ¶
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 ¶
type DefaultServiceInstance struct { ID string ServiceName string Host string Port int Enable bool Healthy bool Metadata map[string]string ServiceMetadata *common.MetadataInfo Address string }
DefaultServiceInstance the default implementation of ServiceInstance or change the ServiceInstance to be struct???
func (*DefaultServiceInstance) Copy ¶
func (d *DefaultServiceInstance) Copy(endpoint *Endpoint) ServiceInstance
Copy return a instance with different port
func (*DefaultServiceInstance) GetAddress ¶
func (d *DefaultServiceInstance) GetAddress() string
GetAddress will return the ip:Port
func (*DefaultServiceInstance) GetEndPoints ¶
func (d *DefaultServiceInstance) GetEndPoints() []*Endpoint
GetEndPoints get end points from metadata
func (*DefaultServiceInstance) GetHost ¶
func (d *DefaultServiceInstance) GetHost() string
GetHost will return the hostname
func (*DefaultServiceInstance) GetID ¶
func (d *DefaultServiceInstance) GetID() string
GetID will return this instance's id. It should be unique.
func (*DefaultServiceInstance) GetMetadata ¶
func (d *DefaultServiceInstance) GetMetadata() map[string]string
GetMetadata will return the metadata, it will never return nil
func (*DefaultServiceInstance) GetPort ¶
func (d *DefaultServiceInstance) GetPort() int
GetPort will return the port.
func (*DefaultServiceInstance) GetServiceName ¶
func (d *DefaultServiceInstance) GetServiceName() string
GetServiceName will return the serviceName
func (*DefaultServiceInstance) IsEnable ¶
func (d *DefaultServiceInstance) IsEnable() bool
IsEnable will return the enable status of this instance
func (*DefaultServiceInstance) IsHealthy ¶
func (d *DefaultServiceInstance) IsHealthy() bool
IsHealthy will return the value represent the instance whether healthy or not
func (*DefaultServiceInstance) SetServiceMetadata ¶
func (d *DefaultServiceInstance) SetServiceMetadata(m *common.MetadataInfo)
SetServiceMetadata save metadata in instance
func (*DefaultServiceInstance) ToURLs ¶
func (d *DefaultServiceInstance) ToURLs() []*common.URL
ToURLs
type Endpoint ¶
type Endpoint struct { Port int `json:"port, omitempty"` Protocol string `json:"protocol, omitempty"` }
nolint
type FacadeBasedRegistry ¶
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 ¶
type Listener interface { // Next returns next service event once received Next() (*ServiceEvent, error) // Close closes this listener Close() }
Listener Deprecated!
type MockRegistry ¶
type MockRegistry struct {
// contains filtered or unexported fields
}
MockRegistry is used as mock registry
func (*MockRegistry) IsAvailable ¶
func (r *MockRegistry) IsAvailable() bool
IsAvailable is use for determine a mock registry available
func (*MockRegistry) Register ¶
func (*MockRegistry) Register(url *common.URL) error
Register is used as a mock registry
func (*MockRegistry) Subscribe ¶
func (r *MockRegistry) Subscribe(url *common.URL, notifyListener NotifyListener) error
nolint
func (*MockRegistry) UnSubscribe ¶
func (r *MockRegistry) UnSubscribe(url *common.URL, notifyListener NotifyListener) error
UnSubscribe :
type NotifyListener ¶
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
type RegistryFactory ¶
type RegistryFactory interface { // GetRegistries get registries GetRegistries() []Registry }
RegistryFactory
type ServiceDiscovery ¶
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 // 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 ¶
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 ¶
type ServiceEvent struct { Action remoting.EventType Service *common.URL // contains filtered or unexported fields }
ServiceEvent includes create, update, delete event
func (*ServiceEvent) Key ¶
func (e *ServiceEvent) Key() string
Key() generate the key for service.Key(). It is cached once.
func (*ServiceEvent) String ¶
func (e *ServiceEvent) String() string
String return the description of event
func (*ServiceEvent) Update ¶
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 ¶
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 ¶
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 ¶
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 ¶
type ServiceInstancesChangedEvent struct { observer.BaseEvent ServiceName string Instances []ServiceInstance }
ServiceInstancesChangedEvent represents service instances make some changing
func NewServiceInstancesChangedEvent ¶
func NewServiceInstancesChangedEvent(serviceName string, instances []ServiceInstance) *ServiceInstancesChangedEvent
NewServiceInstancesChangedEvent will create the ServiceInstanceChangedEvent instance
func (*ServiceInstancesChangedEvent) String ¶
func (s *ServiceInstancesChangedEvent) String() string
String return the description of the event
type ServiceInstancesChangedListener ¶
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