You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by la...@apache.org on 2022/02/18 12:44:13 UTC
[dubbo-go] branch 3.0 updated: dynamically update consumer request timeout
This is an automated email from the ASF dual-hosted git repository.
laurence pushed a commit to branch 3.0
in repository https://gitbox.apache.org/repos/asf/dubbo-go.git
The following commit(s) were added to refs/heads/3.0 by this push:
new 3684c78 dynamically update consumer request timeout
new 1a79c4f Merge pull request #1710 from sunrui1225/feature/triple_timeout_dynamic_update
3684c78 is described below
commit 3684c788b14ccc44a65380ec38a1e733f41f96a9
Author: ruishansun <sr...@163.com>
AuthorDate: Thu Jan 13 16:14:19 2022 +0800
dynamically update consumer request timeout
---
config/consumer_config.go | 8 ++++++++
config/registry_config.go | 6 +++---
config/root_config.go | 7 ++++---
config/root_config_test.go | 1 +
config/testdata/root_config_test.yml | 8 +++++++-
5 files changed, 23 insertions(+), 7 deletions(-)
diff --git a/config/consumer_config.go b/config/consumer_config.go
index f9344f3..adda73a 100644
--- a/config/consumer_config.go
+++ b/config/consumer_config.go
@@ -239,3 +239,11 @@ func (ccb *ConsumerConfigBuilder) SetRootConfig(rootConfig *RootConfig) *Consume
func (ccb *ConsumerConfigBuilder) Build() *ConsumerConfig {
return ccb.consumerConfig
}
+
+// DynamicUpdateProperties dynamically update properties.
+func (cc *ConsumerConfig) DynamicUpdateProperties(newConsumerConfig *ConsumerConfig) {
+ if newConsumerConfig != nil && newConsumerConfig.RequestTimeout != cc.RequestTimeout {
+ cc.RequestTimeout = newConsumerConfig.RequestTimeout
+ logger.Infof("ConsumerConfig's RequestTimeout was dynamically updated, new value:%v", cc.RequestTimeout)
+ }
+}
diff --git a/config/registry_config.go b/config/registry_config.go
index 506dc79..74ab930 100644
--- a/config/registry_config.go
+++ b/config/registry_config.go
@@ -398,11 +398,11 @@ func (rcb *RegistryConfigBuilder) Build() *RegistryConfig {
return rcb.registryConfig
}
-// UpdateProperties update registry
-func (c *RegistryConfig) UpdateProperties(updateRegistryConfig *RegistryConfig) {
+// DynamicUpdateProperties update registry
+func (c *RegistryConfig) DynamicUpdateProperties(updateRegistryConfig *RegistryConfig) {
// if nacos's registry timeout not equal local root config's registry timeout , update.
if updateRegistryConfig != nil && updateRegistryConfig.Timeout != c.Timeout {
c.Timeout = updateRegistryConfig.Timeout
- logger.Infof("CenterConfig process update timeout, new value:%v", c.Timeout)
+ logger.Infof("RegistryConfigs Timeout was dynamically updated, new value:%v", c.Timeout)
}
}
diff --git a/config/root_config.go b/config/root_config.go
index 7450a32..e063295 100644
--- a/config/root_config.go
+++ b/config/root_config.go
@@ -395,10 +395,11 @@ func (rc *RootConfig) Process(event *config_center.ConfigChangeEvent) {
logger.Errorf("CenterConfig process unmarshalConf failed, got error %#v", err)
return
}
-
- // update register
+ // dynamically update register
for registerId, updateRegister := range updateRootConfig.Registries {
register := rc.Registries[registerId]
- register.UpdateProperties(updateRegister)
+ register.DynamicUpdateProperties(updateRegister)
}
+ // dynamically update consumer
+ rc.Consumer.DynamicUpdateProperties(updateRootConfig.Consumer)
}
diff --git a/config/root_config_test.go b/config/root_config_test.go
index bf38868..1b309d1 100644
--- a/config/root_config_test.go
+++ b/config/root_config_test.go
@@ -46,5 +46,6 @@ func TestGoConfigProcess(t *testing.T) {
c := &config_center.ConfigChangeEvent{Key: "test", Value: string(bs)}
rc.rootConfig.Process(c)
assert.Equal(t, rc.rootConfig.Registries["demoZK"].Timeout, "11s")
+ assert.Equal(t, rc.rootConfig.Consumer.RequestTimeout, "6s")
}
diff --git a/config/testdata/root_config_test.yml b/config/testdata/root_config_test.yml
index 285b79c..9acfc49 100644
--- a/config/testdata/root_config_test.yml
+++ b/config/testdata/root_config_test.yml
@@ -14,4 +14,10 @@ dubbo:
services:
GreeterProvider:
protocol-ids: triple
- interface: com.apache.dubbo.sample.basic.IGreeter # must be compatible with grpc or dubbo-java
\ No newline at end of file
+ interface: com.apache.dubbo.sample.basic.IGreeter # must be compatible with grpc or dubbo-java
+ consumer:
+ request-timeout: 6s
+ references:
+ GreeterClientImpl:
+ protocol: tri
+ interface: com.apache.dubbo.HelloService # must be compatible with grpc or dubbo-java
\ No newline at end of file