diff --git a/config/config_center_config.go b/config/config_center_config.go index 9a0bd1ee1dcfdd37476540568baaadb824db2d72..ed43558956a181e669a1a8936182b65a2fb2766c 100644 --- a/config/config_center_config.go +++ b/config/config_center_config.go @@ -35,7 +35,7 @@ type ConfigCenterConfig struct { Username string `yaml:"username" json:"username,omitempty"` Password string `yaml:"password" json:"password,omitempty"` ConfigFile string `default:"dubbo.properties" yaml:"config_file" json:"config_file,omitempty"` - AppConfigFile string `yaml:"app_config_file" json:"app_config_file,omitempty"` + AppConfigFile string `default:"dubbo.properties" yaml:"app_config_file" json:"app_config_file,omitempty"` TimeoutStr string `yaml:"timeout" json:"timeout,omitempty"` timeout time.Duration } diff --git a/config/config_loader.go b/config/config_loader.go index 8561828ae07d01ccd292d15aa2980a50266725b3..716e3d089b05d5a16b035a2747813ede891f81c7 100644 --- a/config/config_loader.go +++ b/config/config_loader.go @@ -60,12 +60,21 @@ func checkRegistries(registries map[string]*RegistryConfig, singleRegistry *Regi } } +func checkApplicationName(config *ApplicationConfig) { + if len(config.Name) == 0 { + errMsg := "application config must not be nil, pls check your configuration" + logger.Errorf(errMsg) + panic(errMsg) + } +} + // Dubbo Init func Load() { // reference config if consumerConfig == nil { logger.Warnf("consumerConfig is nil!") } else { + checkApplicationName(consumerConfig.ApplicationConfig) if err := configCenterRefreshConsumer(); err != nil { logger.Errorf("[consumer config center refresh] %#v", err) } @@ -98,7 +107,9 @@ func Load() { checkok = false count++ if count > maxWait { - panic(fmt.Sprintf("Failed to check the status of the service %v . No provider available for the service to the consumer use dubbo version %v", refconfig.InterfaceName, constant.Version)) + errMsg := fmt.Sprintf("Failed to check the status of the service %v . No provider available for the service to the consumer use dubbo version %v", refconfig.InterfaceName, constant.Version) + logger.Error(errMsg) + panic(errMsg) } time.Sleep(time.Second * 1) break @@ -119,6 +130,7 @@ func Load() { if providerConfig == nil { logger.Warnf("providerConfig is nil!") } else { + checkApplicationName(providerConfig.ApplicationConfig) if err := configCenterRefreshProvider(); err != nil { logger.Errorf("[provider config center refresh] %#v", err) } diff --git a/config/config_loader_test.go b/config/config_loader_test.go index 3562bf5a189f02a8db61a2aa840e6f632efb63ba..498f82678070d194e3ffe1539064be7aec19f719 100644 --- a/config/config_loader_test.go +++ b/config/config_loader_test.go @@ -213,10 +213,12 @@ func TestConfigLoaderWithConfigCenterSingleRegistry(t *testing.T) { assert.Equal(t, ProviderConfig{}, GetProviderConfig()) err = ConsumerInit(conPath) + checkApplicationName(consumerConfig.ApplicationConfig) configCenterRefreshConsumer() checkRegistries(consumerConfig.Registries, consumerConfig.Registry) assert.NoError(t, err) err = ProviderInit(proPath) + checkApplicationName(providerConfig.ApplicationConfig) configCenterRefreshProvider() checkRegistries(providerConfig.Registries, providerConfig.Registry) assert.NoError(t, err) diff --git a/config/testdata/consumer_config_with_configcenter.yml b/config/testdata/consumer_config_with_configcenter.yml index c6505e4492887cc6602ab0b2ee9a9fbd9fdce9c9..7ee4ce7029dc4acc7132efdf9c779df8c3939f6e 100644 --- a/config/testdata/consumer_config_with_configcenter.yml +++ b/config/testdata/consumer_config_with_configcenter.yml @@ -1,5 +1,7 @@ # dubbo client yaml configure file +application: + name: "BDTService" config_center: protocol: "mock" address: "127.0.0.1"