dubbo

package
v1.6.0 Latest Latest
Warning

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

Go to latest
Published: May 25, 2023 License: Apache-2.0 Imports: 20 Imported by: 1

README

Notice

This package is extracted from github.com/apache/dubbo-go

  1. Import paths were edited to reduce the dependencies.

  2. The most init funcitons were removed

  3. ETCD, consul, nacos, kubernetes were removed

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

View Source
var (
	RegisteredError = errors.New("already registered")
)

Functions

This section is empty.

Types

type BaseRegistry

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

func (r *BaseRegistry) Destroy()

Destroy for graceful down

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 ConditionalEventListener

type ConditionalEventListener interface {
	EventListener
	// Accept will make the decision whether it should handle this event
	Accept(e Event) bool
}

ConditionalEventListener only handle the event which it can handle

type DefaultServiceInstance

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

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

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

type Event

type Event interface {
	fmt.Stringer
	GetSource() interface{}
	GetTimestamp() time.Time
}

Event is align with Event interface in Java. it's the top abstraction Align with 2.7.5

type EventListener

type EventListener interface {
	gxsort.Prioritizer
	// OnEvent handle this event
	OnEvent(e Event) error
}

EventListener is an new interface used to align with dubbo 2.7.5 It contains the Prioritized means that the listener has its priority

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() (*ServiceEvent, error)
	Close()
}

Listener Deprecated!

type MockRegistry

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

MockRegistry ...

func (*MockRegistry) Destroy

func (r *MockRegistry) Destroy()

Destroy ...

func (*MockRegistry) GetUrl

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

GetUrl ...

func (*MockRegistry) IsAvailable

func (r *MockRegistry) IsAvailable() bool

IsAvailable ...

func (*MockRegistry) MockEvent

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

MockEvent ...

func (*MockRegistry) Register

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

Register ...

func (*MockRegistry) Subscribe

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

Subscribe ...

func (*MockRegistry) UnRegister

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

UnRegister

func (*MockRegistry) UnSubscribe

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

UnSubscribe :

type NotifyListener

type NotifyListener interface {
	Notify(*ServiceEvent)
}

NotifyListener ...

type Registry

type Registry interface {
	common.Node
	//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

	//Will relace 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

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

NewMockRegistry ...

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 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
}

type ServiceEvent

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

ServiceEvent ...

func (ServiceEvent) String

func (e ServiceEvent) String() string

String return the description of event

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
}

type ServiceInstancesChangedEvent

type ServiceInstancesChangedEvent struct {
	ServiceName string
	Instances   []ServiceInstance
	// contains filtered or unexported fields
}

ServiceInstancesChangedEvent represents service instances make some changing

func NewServiceInstancesChangedEvent

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

NewServiceInstancesChangedEvent will create the ServiceInstanceChangedEvent instance

func (*ServiceInstancesChangedEvent) GetSource

func (b *ServiceInstancesChangedEvent) GetSource() interface{}

GetSource return the source

func (*ServiceInstancesChangedEvent) GetTimestamp

func (b *ServiceInstancesChangedEvent) GetTimestamp() time.Time

GetTimestamp return the timestamp when the event is created

func (*ServiceInstancesChangedEvent) String

String return the description of the event

type ServiceInstancesChangedListener

type ServiceInstancesChangedListener struct {
	ServiceName string
}

TODO (implement ConditionalEventListener)

Jump to

Keyboard shortcuts

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