Configuration File

Develop microservice applications using the dubbogo.yml configuration file.

1. Framework Configuration

The Dubbo-go framework relies on configuration for startup. The configuration includes various capabilities that the developer wishes to use within the framework.

Configuration Format

yaml

Configuration Path

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.

Configuration Root Structure

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.

2. Configuration API

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.

3. Configuration Center

Developers can place the configuration in a configuration center for easier management and modification.

Root Configuration

Client Configuration

Server Configuration

Registry Configuration

Using Configuration API

  • Clients use the configuration API to set up the registry.

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).

  1. rc := config.NewRootConfigBuilder().
  2. SetConsumer(config.NewConsumerConfigBuilder().
  3. SetRegistryIDs("zookeeperID"). // use defined registryID
  4. Build()).
  5. AddRegistry("zookeeperID", config.NewRegistryConfigWithProtocolDefaultPort("zookeeper")).
  6. Build()

All interfaces: You can configure through the rich interfaces provided by RegistryConfigBuilder.

  1. rc := config.NewRootConfigBuilder().
  2. SetConsumer(config.NewConsumerConfigBuilder().
  3. SetRegistryIDs("nacosRegistryID"). // use defined registryID
  4. AddReference("GreeterClientImpl", /*...*/).
  5. Build()
  6. AddRegistry("nacosRegistryID", config.NewRegistryConfigBuilder().
  7. SetProtocol("nacos").
  8. SetAddress("127.0.0.1:8848").
  9. SetGroup("dubbo-go").
  10. SetNamespace("dubbo").
  11. SetUsername("admin").
  12. SetPassword("admin").
  13. SetTimeout("3s").
  14. Build()).
  15. Build()
  • Servers use the configuration API to set up the configuration center.

Simple interface config.NewRegistryConfigWithProtocolDefaultPort.

  1. rc := config.NewRootConfigBuilder().
  2. SetProvider(config.NewProviderConfigBuilder().
  3. AddService("GreeterProvider", /*...*/).
  4. SetRegistryIDs("registryKey"). // use defined registryID
  5. Build()).
  6. AddRegistry("registryKey", config.NewRegistryConfigWithProtocolDefaultPort("zookeeper")).
  7. Build()

All interfaces: You can configure through the rich interfaces provided by RegistryConfigBuilder.

  1. rc := config.NewRootConfigBuilder().
  2. SetProvider(config.NewProviderConfigBuilder().
  3. AddService("GreeterProvider", /*...*/).
  4. SetRegistryIDs("registryKey"). // use defined registryID
  5. Build()).
  6. AddRegistry("registryKey", config.NewRegistryConfigBuilder().
  7. SetProtocol("nacos").
  8. SetAddress("127.0.0.1:8848").
  9. SetGroup("dubbo-go").
  10. SetNamespace("dubbo").
  11. SetUsername("admin").
  12. SetPassword("admin").
  13. SetTimeout("3s").
  14. Build()).
  15. Build()

Network Protocol

Configuration File

Using Configuration API

  • Clients use the configuration API to set the network protocol.
  1. rc := config.NewRootConfigBuilder().
  2. SetConsumer(config.NewConsumerConfigBuilder().
  3. AddReference("GreeterClientImpl", config.NewReferenceConfigBuilder().
  4. SetInterface("org.apache.dubbo.UserProvider").
  5. SetProtocol("tri"). // set reference protocol to triple
  6. Build()).
  7. Build()).
  8. Build()
  • Servers use the configuration API to set the network protocol.
  1. rc := config.NewRootConfigBuilder().
  2. SetProvider(config.NewProviderConfigBuilder().
  3. AddService("GreeterProvider", config.NewServiceConfigBuilder().
  4. SetInterface("org.apache.dubbo.UserProvider").
  5. SetProtocolIDs("tripleProtocolKey"). // use protocolID 'tripleProtocolKey'
  6. Build()).
  7. Build()).
  8. AddProtocol("tripleProtocolKey", config.NewProtocolConfigBuilder(). // define protocol config with protocolID 'tripleProtocolKey'
  9. SetName("tri"). // set service protocol to triple
  10. Build()).
  11. Build()

Use the dubbogo.yml Configuration File to Develop Applications

Use the dubbogo.yml configuration file to develop applications

Remote Configuration File

Load the dubbogo.yaml configuration file remotely

Feedback

Was this page helpful?

Yes No

Last modified September 30, 2024: Update & Translate Overview Docs (#3040) (d37ebceaea7)