配置项参考

根配置

客户端配置

服务端配置

注册中心配置

使用配置 API

  • 客户端使用配置 API 设置注册中心

可通过调用config.NewRegistryConfigWithProtocolDefaultPort方法,快速设置用于调试的注册中心,支持zookeeper(127.0.0.1:2181) 和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()

全部接口:可通过调用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()
  • 服务端使用配置 API 设置配置中心

简易接口 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()

全部接口:可通过调用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()

网络协议

配置文件

使用配置 API

  • 客户端使用配置 API 设置网络协议
  1. rc := config.NewRootConfigBuilder().
  2. SetConsumer(config.NewConsumerConfigBuilder().
  3. AddReference("GreeterClientImpl", config.NewReferenceConfigBuilder().
  4. SetInterface("org.apache.dubbo.UserProvider").
  5. SetProtocol("tri"). // set reference protcol to triple
  6. Build()).
  7. Build()).
  8. Build()
  • 服务端使用配置 API 设置网络协议
  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()

最后修改 December 16, 2022: Fix check (#1736) (97972c1)