Use the dubbogo.yml Configuration File to Develop Applications
Use the dubbogo.yml configuration file to develop applications
The Dubbo-go framework relies on configuration for startup. The configuration includes various capabilities that the developer wishes to use within the framework.
yaml
By default, the framework configuration is loaded from ../conf/dubbogo.yaml
.
You can modify the configuration file path by specifying the environment variable: DUBBO_GO_CONFIG_PATH=$(your_config_path)/dubbogo.yaml.
Located at dubbo.apache.org/dubbo-go/v3/config/root_config.go: RootConfig.
When the framework loads, any form of configuration will be parsed into RootConfig and loaded in the RootConfig.Init method.
Developers can build configurations using APIs to start the framework. This method is more suitable when dubbo-go is introduced as a third-party component.
Developers can place the configuration in a configuration center for easier management and modification.
You can quickly set up the registry for debugging by calling the config.NewRegistryConfigWithProtocolDefaultPort method, supporting zookeeper (127.0.0.1:2181) and nacos (127.0.0.1:8848).
rc := config.NewRootConfigBuilder().
SetConsumer(config.NewConsumerConfigBuilder().
SetRegistryIDs("zookeeperID"). // use defined registryID
Build()).
AddRegistry("zookeeperID", config.NewRegistryConfigWithProtocolDefaultPort("zookeeper")).
Build()
All interfaces: You can configure through the rich interfaces provided by RegistryConfigBuilder.
rc := config.NewRootConfigBuilder().
SetConsumer(config.NewConsumerConfigBuilder().
SetRegistryIDs("nacosRegistryID"). // use defined registryID
AddReference("GreeterClientImpl", /*...*/).
Build()
AddRegistry("nacosRegistryID", config.NewRegistryConfigBuilder().
SetProtocol("nacos").
SetAddress("127.0.0.1:8848").
SetGroup("dubbo-go").
SetNamespace("dubbo").
SetUsername("admin").
SetPassword("admin").
SetTimeout("3s").
Build()).
Build()
Simple interface config.NewRegistryConfigWithProtocolDefaultPort.
rc := config.NewRootConfigBuilder().
SetProvider(config.NewProviderConfigBuilder().
AddService("GreeterProvider", /*...*/).
SetRegistryIDs("registryKey"). // use defined registryID
Build()).
AddRegistry("registryKey", config.NewRegistryConfigWithProtocolDefaultPort("zookeeper")).
Build()
All interfaces: You can configure through the rich interfaces provided by RegistryConfigBuilder.
rc := config.NewRootConfigBuilder().
SetProvider(config.NewProviderConfigBuilder().
AddService("GreeterProvider", /*...*/).
SetRegistryIDs("registryKey"). // use defined registryID
Build()).
AddRegistry("registryKey", config.NewRegistryConfigBuilder().
SetProtocol("nacos").
SetAddress("127.0.0.1:8848").
SetGroup("dubbo-go").
SetNamespace("dubbo").
SetUsername("admin").
SetPassword("admin").
SetTimeout("3s").
Build()).
Build()
rc := config.NewRootConfigBuilder().
SetConsumer(config.NewConsumerConfigBuilder().
AddReference("GreeterClientImpl", config.NewReferenceConfigBuilder().
SetInterface("org.apache.dubbo.UserProvider").
SetProtocol("tri"). // set reference protocol to triple
Build()).
Build()).
Build()
rc := config.NewRootConfigBuilder().
SetProvider(config.NewProviderConfigBuilder().
AddService("GreeterProvider", config.NewServiceConfigBuilder().
SetInterface("org.apache.dubbo.UserProvider").
SetProtocolIDs("tripleProtocolKey"). // use protocolID 'tripleProtocolKey'
Build()).
Build()).
AddProtocol("tripleProtocolKey", config.NewProtocolConfigBuilder(). // define protocol config with protocolID 'tripleProtocolKey'
SetName("tri"). // set service protocol to triple
Build()).
Build()
Use the dubbogo.yml configuration file to develop applications
Load the dubbogo.yaml configuration file remotely