Remote Configuration File

Load the dubbogo.yaml configuration file remotely

The Dubbo framework supports preloading the contents of the configuration file ‘dubbogo.yaml’ into the configuration center, and then merging it with local configurations through remote loading, thus achieving some dynamic and centralized management of configurations.

Notice

Applications that have correctly configured the config-center address will prioritize loading the entire configuration file from the configuration center.

You can view the full example source code here. This article demonstrates using Zookeeper, and the usage of Nacos is similar, with specific source code examples available at the above address.

Enable Configuration Center

In the dubbo-go application, enable the configuration center with dubbo.WithConfigCenter():

  1. ins, err := dubbo.NewInstance(
  2. dubbo.WithConfigCenter(
  3. config_center.WithZookeeper(),
  4. config_center.WithDataID("dubbo-go-samples-configcenter-zookeeper-server"),
  5. config_center.WithAddress("127.0.0.1:2181"),
  6. config_center.WithGroup("dubbogo"),
  7. ),
  8. )
  9. if err != nil {
  10. panic(err)
  11. }

Before running the application, pre-write the following configuration into the Zookeeper cluster at the path /dubbo/config/dubbogo/dubbo-go-samples-configcenter-zookeeper-server:

  1. dubbo:
  2. registries:
  3. demoZK:
  4. protocol: zookeeper
  5. timeout: 3s
  6. address: '127.0.0.1:2181'
  7. protocols:
  8. triple:
  9. name: tri
  10. port: 20000

Start the Server and Register the Service

  1. srv, err := ins.NewServer()
  2. if err != nil {
  3. panic(err)
  4. }
  5. if err := greet.RegisterGreetServiceHandler(srv, &GreetTripleServer{}); err != nil {
  6. panic(err)
  7. }
  8. if err := srv.Serve(); err != nil {
  9. logger.Error(err)
  10. }

You will find that the application has read the remote dubbogo.yml file and connected to the registered center address, protocol, and port configured in the file.

Start the Client

  1. $ go run ./go-client/cmd/main.go

Expected Output

  1. Greet response: greeting:"hello world"

Feedback

Was this page helpful?

Yes No

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