Related samples:
Related documentation:
In current Dubbo Go, the registry layer is not only about interface-level address registration. It also participates in application-level service discovery, metadata bootstrap, subscription refresh, and registry-backed protocol export.
The main interface is defined in registry/registry.go:
type Registry interface {
common.Node
Register(url *common.URL) error
UnRegister(url *common.URL) error
Subscribe(*common.URL, NotifyListener) error
UnSubscribe(*common.URL, NotifyListener) error
LoadSubscribeInstances(*common.URL, NotifyListener) error
}
Compared with older explanations, LoadSubscribeInstances(...) is now part of the contract. It exists because subscription is asynchronous, and Dubbo Go may need an initial synchronous load before the normal subscription stream catches up.
The registry layer now covers several related responsibilities:
In source layout, the main related packages are:
registryregistry/protocolregistry/servicediscoveryregistry/directoryCurrent Dubbo Go supports multiple registration models through registry/options.go:
registry.WithRegisterService()registry.WithRegisterInterface()registry.WithRegisterServiceAndInterface()These correspond to:
service: register application-level instancesinterface: register interface-level provider URLsall: register both during migrationThis is one of the biggest differences from older Dubbo Go documentation, which mostly described only interface-level registration.
At a high level:
server and protocol.registry/protocol coordinates registration and metadata reporting.registry/directory receives address updates and maintains the effective provider list.With application-level discovery, the consumer may first resolve service-to-application mapping and then recover concrete callable endpoints through metadata.
Built-in implementations are registered through package initialization:
registry/nacosregistry/zookeeperregistry/etcdv3registry/polarisregistry/servicediscoveryThey are exposed through common/extension.SetRegistry(...) and commonly loaded through:
import _ "dubbo.apache.org/dubbo-go/v3/imports"
In API mode, registries are configured with:
dubbo.WithRegistry(...) at instance levelclient.WithRegistry(...) or client.WithRegistryIDs(...) on referencesserver.WithRegistry(...) or server.WithRegistryIDs(...) on servicesIn configuration-file mode, registries live under RootConfig.Registries.
That split explains why the registry layer appears both as a top-level application concern and as a per-service or per-reference selector.