Skip to content
Snippets Groups Projects
Commit 72067dcd authored by vito.he's avatar vito.he
Browse files

Mod:add application name check

parent 1ee6882c
No related branches found
No related tags found
No related merge requests found
......@@ -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
}
......
......@@ -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)
}
......
......@@ -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)
......
# dubbo client yaml configure file
application:
name: "BDTService"
config_center:
protocol: "mock"
address: "127.0.0.1"
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment