diff --git a/config/service_config.go b/config/service_config.go index c17846322e20120bfdf00f1afe24bd20efe7510b..a2ed13966072f319693671137ba991978a0dcdb9 100644 --- a/config/service_config.go +++ b/config/service_config.go @@ -117,8 +117,12 @@ func (srvconfig *ServiceConfig) Export() error { regUrls := loadRegistries(srvconfig.Registry, providerConfig.Registries, common.PROVIDER) urlMap := srvconfig.getUrlMap() - - for _, proto := range loadProtocol(srvconfig.Protocol, providerConfig.Protocols) { + protocolConfigs := loadProtocol(srvconfig.Protocol, providerConfig.Protocols) + if len(protocolConfigs) == 0 { + logger.Warnf("The service %v's '%v' protocols don't has right protocolConfigs ", srvconfig.InterfaceName, srvconfig.Protocol) + return nil + } + for _, proto := range protocolConfigs { // registry the service reflect methods, err := common.ServiceMap.Register(proto.Name, srvconfig.rpcService) if err != nil { diff --git a/config/service_config_test.go b/config/service_config_test.go index 8ae67533bd1cdd1f9170efd762de51d371d0ad38..6f3230890348e77ea26c9c0eaf9165090c8cd09f 100644 --- a/config/service_config_test.go +++ b/config/service_config_test.go @@ -93,6 +93,30 @@ func doInitProvider() { }, }, }, + "MockServiceNoRightProtocol": { + InterfaceName: "com.MockService", + Protocol: "mock1", + Registry: "shanghai_reg1,shanghai_reg2,hangzhou_reg1,hangzhou_reg2", + Cluster: "failover", + Loadbalance: "random", + Retries: "3", + Group: "huadong_idc", + Version: "1.0.0", + Methods: []*MethodConfig{ + { + Name: "GetUser", + Retries: "2", + Loadbalance: "random", + Weight: 200, + }, + { + Name: "GetUser1", + Retries: "2", + Loadbalance: "random", + Weight: 200, + }, + }, + }, }, Protocols: map[string]*ProtocolConfig{ "mock": {