註冊中心

Dubbogo 為註冊中心抽象了一套介面如下:

// Registry Extension - 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
}

該介面主要包含四個方法,分別是註冊、反註冊、訂閱、取消訂閱。顧名思義,概括了客戶端和伺服器端與註冊中心互動的動作。針對普通介面級服務註冊發現場景,在 Provider 服務啟動時,會將自身服務介面資訊抽象為一個 URL,該 URL 包含了客戶端發起呼叫所需的所有資訊(IP、埠、協定等),伺服器端的註冊中心組件會將該 URL 寫入註冊中心(例如 ZooKeeper)。客戶端啟動後,在服務引用 Refer 步驟會透過註冊中心組件訂閱(Subscribe)需要的服務資訊,獲取到的服務資訊以非同步事件更新的形式寫入客戶端快取,從而在服務發現成功後,可以根據拿到的服務 URL 參數,向對應服務提供者發起呼叫。


最後修改日期:2023 年 1 月 2 日:增強 Dubbogo 文件 (#1800) (71c8e722740)