diff --git a/config/rpc_service.go b/config/rpc_service.go index f39a4ec9b35f9a391a3f8470c07e74f1509658c9..f56ce1f1f98c0cb11ef2f7f12589169cae7b5bf9 100644 --- a/config/rpc_service.go +++ b/config/rpc_service.go @@ -16,7 +16,7 @@ import ( // rpc service interface type RPCService interface { - Service() string // Service interfaceName + Service() string // Service InterfaceName Version() string } diff --git a/config/support/config_loader.go b/config/support/config_loader.go index 4e8ab5d7da58708a713aeed05fcb93cd46df9146..0f21f643531b5917b19a21535849b67456d3ae35 100644 --- a/config/support/config_loader.go +++ b/config/support/config_loader.go @@ -82,16 +82,11 @@ func consumerInit(confConFile string) error { if err != nil { return fmt.Errorf("ioutil.ReadFile(file:%s) = error:%s", confConFile, jerrors.ErrorStack(err)) } + consumerConfig = &ConsumerConfig{} err = yaml.Unmarshal(confFileStream, consumerConfig) if err != nil { return fmt.Errorf("yaml.Unmarshal() = error:%s", jerrors.ErrorStack(err)) } - //鍔ㄦ€佸姞杞絪ervice config end - //for _, config := range consumerConfig.Registries { - // if config.Timeout, err = time.ParseDuration(config.TimeoutStr); err != nil { - // return fmt.Errorf("time.ParseDuration(Registry_Config.Timeout:%#v) = error:%s", config.TimeoutStr, err) - // } - //} gxlog.CInfo("consumer config{%#v}\n", consumerConfig) return nil @@ -110,6 +105,7 @@ func providerInit(confProFile string) error { if err != nil { return fmt.Errorf("ioutil.ReadFile(file:%s) = error:%s", confProFile, jerrors.ErrorStack(err)) } + providerConfig = &ProviderConfig{} err = yaml.Unmarshal(confFileStream, providerConfig) if err != nil { return fmt.Errorf("yaml.Unmarshal() = error:%s", jerrors.ErrorStack(err)) @@ -156,6 +152,10 @@ func SetConsumerConfig(c ConsumerConfig) { consumerConfig = &c } func GetConsumerConfig() ConsumerConfig { + if consumerConfig == nil { + log.Warn("consumerConfig is nil!") + return ConsumerConfig{} + } return *consumerConfig } @@ -164,6 +164,10 @@ func GetConsumerConfig() ConsumerConfig { ///////////////////////// type ProviderConfig struct { + // pprof + Pprof_Enabled bool `default:"false" yaml:"pprof_enabled" json:"pprof_enabled,omitempty"` + Pprof_Port int `default:"10086" yaml:"pprof_port" json:"pprof_port,omitempty"` + ApplicationConfig ApplicationConfig `yaml:"application_config" json:"application_config,omitempty"` Path string `yaml:"path" json:"path,omitempty"` Registries []RegistryConfig `yaml:"registries" json:"registries,omitempty"` @@ -175,21 +179,25 @@ func SetProviderConfig(p ProviderConfig) { providerConfig = &p } func GetProviderConfig() ProviderConfig { + if providerConfig == nil { + log.Warn("providerConfig is nil!") + return ProviderConfig{} + } return *providerConfig } type ProtocolConfig struct { - name string `required:"true" yaml:"name" json:"name,omitempty"` - ip string `required:"true" yaml:"ip" json:"ip,omitempty"` - port string `required:"true" yaml:"port" json:"port,omitempty"` - contextPath string `required:"true" yaml:"contextPath" json:"contextPath,omitempty"` + Name string `required:"true" yaml:"name" json:"name,omitempty"` + Ip string `required:"true" yaml:"ip" json:"ip,omitempty"` + Port string `required:"true" yaml:"port" json:"port,omitempty"` + ContextPath string `required:"true" yaml:"contextPath" json:"contextPath,omitempty"` } func loadProtocol(protocolsIds string, protocols []ProtocolConfig) []ProtocolConfig { returnProtocols := []ProtocolConfig{} for _, v := range strings.Split(protocolsIds, ",") { for _, prot := range protocols { - if v == prot.name { + if v == prot.Name { returnProtocols = append(returnProtocols, prot) } } @@ -200,27 +208,37 @@ func loadProtocol(protocolsIds string, protocols []ProtocolConfig) []ProtocolCon // Dubbo Init func Load() (map[string]*ReferenceConfig, map[string]*ServiceConfig) { - refMap := make(map[string]*ReferenceConfig) - srvMap := make(map[string]*ServiceConfig) + var refMap map[string]*ReferenceConfig + var srvMap map[string]*ServiceConfig // reference config - length := len(consumerConfig.References) - for index := 0; index < length; index++ { - con := &consumerConfig.References[index] - con.Implement(conServices[con.interfaceName]) - con.Refer() - refMap[con.interfaceName] = con + if consumerConfig == nil { + log.Warn("consumerConfig is nil!") + } else { + refMap = make(map[string]*ReferenceConfig) + length := len(consumerConfig.References) + for index := 0; index < length; index++ { + con := &consumerConfig.References[index] + con.Implement(conServices[con.InterfaceName]) + con.Refer() + refMap[con.InterfaceName] = con + } } // service config - length = len(providerConfig.Services) - for index := 0; index < length; index++ { - pro := &providerConfig.Services[index] - pro.Implement(proServices[pro.interfaceName]) - if err := pro.Export(); err != nil { - panic(fmt.Sprintf("service %s export failed! ", pro.interfaceName)) + if providerConfig == nil { + log.Warn("providerConfig is nil!") + } else { + srvMap = make(map[string]*ServiceConfig) + length := len(providerConfig.Services) + for index := 0; index < length; index++ { + pro := &providerConfig.Services[index] + pro.Implement(proServices[pro.InterfaceName]) + if err := pro.Export(); err != nil { + panic(fmt.Sprintf("service %s export failed! ", pro.InterfaceName)) + } + srvMap[pro.InterfaceName] = pro } - srvMap[pro.interfaceName] = pro } return refMap, srvMap diff --git a/config/support/provider_config.yml b/config/support/provider_config.yml index 90fe7dc52ddd92fc9bd9c5c5e64f9a13e8e27da8..48544e9dc447e413767103b5e09eac8378a09cbc 100644 --- a/config/support/provider_config.yml +++ b/config/support/provider_config.yml @@ -51,10 +51,8 @@ services: protocols: - name: "dubbo" - # 濡傛灉鏄�127.0.0.1, java-client灏嗘棤娉曡繛鎺ュ埌go-server ip : "192.168.56.1" port : 20000 - # 鏈瑂erver鑳藉鎻愪緵鎵€鏈夋敮鎸佸悓鏍风殑Protocol鐨剆ervicelist鐨勬湇鍔� - name: "jsonrpc" ip: "127.0.0.1" port: 20001 diff --git a/config/support/reference_config.go b/config/support/reference_config.go index b9ee71db7c1460f70542d8197af14cc17cf6a5a7..04e1ed27b5d3aa929a7476d131fe4de2474ce241 100644 --- a/config/support/reference_config.go +++ b/config/support/reference_config.go @@ -2,13 +2,13 @@ package support import ( "context" - "github.com/dubbo/dubbo-go/cluster/directory" "net/url" "strconv" "time" ) import ( + "github.com/dubbo/dubbo-go/cluster/directory" "github.com/dubbo/dubbo-go/common/constant" "github.com/dubbo/dubbo-go/common/extension" "github.com/dubbo/dubbo-go/common/proxy" @@ -19,25 +19,24 @@ import ( type ReferenceConfig struct { context context.Context pxy *proxy.Proxy - interfaceName string `required:"true" yaml:"interface" json:"interface,omitempty"` - protocol string `yaml:"protocol" json:"protocol,omitempty"` - registries []ConfigRegistry `required:"true" yaml:"registries" json:"registries,omitempty"` - cluster string `yaml:"cluster" json:"cluster,omitempty"` - loadbalance string `yaml:"loadbalance" json:"loadbalance,omitempty"` - retries int64 `yaml:"retries" json:"retries,omitempty"` - group string `yaml:"group" json:"group,omitempty"` - version string `yaml:"version" json:"version,omitempty"` - methods []struct { - name string `yaml:"name" json:"name,omitempty"` - retries int64 `yaml:"retries" json:"retries,omitempty"` - loadbalance string `yaml:"loadbalance" json:"loadbalance,omitempty"` + InterfaceName string `required:"true" yaml:"interface" json:"interface,omitempty"` + Protocol string `yaml:"protocol" json:"protocol,omitempty"` + Registries []ConfigRegistry `required:"true" yaml:"registries" json:"registries,omitempty"` + Cluster string `yaml:"cluster" json:"cluster,omitempty"` + Loadbalance string `yaml:"loadbalance" json:"loadbalance,omitempty"` + Retries int64 `yaml:"retries" json:"retries,omitempty"` + Group string `yaml:"group" json:"group,omitempty"` + Version string `yaml:"version" json:"version,omitempty"` + Methods []struct { + Name string `yaml:"name" json:"name,omitempty"` + Retries int64 `yaml:"retries" json:"retries,omitempty"` + Loadbalance string `yaml:"loadbalance" json:"loadbalance,omitempty"` } `yaml:"methods" json:"methods,omitempty"` async bool `yaml:"async" json:"async,omitempty"` invoker protocol.Invoker } -type ConfigRegistry struct { - string -} + +type ConfigRegistry string func NewReferenceConfig(ctx context.Context) *ReferenceConfig { return &ReferenceConfig{context: ctx} @@ -47,8 +46,8 @@ func (refconfig *ReferenceConfig) Refer() { //棣栧厛鏄痷ser specified SubURL, could be peer-to-peer address, or register center's address. //鍏舵鏄痑ssemble SubURL from register center's configuration妯″紡 - regUrls := loadRegistries(refconfig.registries, consumerConfig.Registries, config.CONSUMER) - url := config.NewURLWithOptions(refconfig.interfaceName, config.WithProtocol(refconfig.protocol), config.WithParams(refconfig.getUrlMap())) + regUrls := loadRegistries(refconfig.Registries, consumerConfig.Registries, config.CONSUMER) + url := config.NewURLWithOptions(refconfig.InterfaceName, config.WithProtocol(refconfig.Protocol), config.WithParams(refconfig.getUrlMap())) //set url to regUrls for _, regUrl := range regUrls { @@ -81,11 +80,11 @@ func (refconfig *ReferenceConfig) getUrlMap() url.Values { urlMap := url.Values{} urlMap.Set(constant.TIMESTAMP_KEY, strconv.FormatInt(time.Now().Unix(), 10)) - urlMap.Set(constant.CLUSTER_KEY, refconfig.cluster) - urlMap.Set(constant.LOADBALANCE_KEY, refconfig.loadbalance) - urlMap.Set(constant.RETRIES_KEY, strconv.FormatInt(refconfig.retries, 10)) - urlMap.Set(constant.GROUP_KEY, refconfig.group) - urlMap.Set(constant.VERSION_KEY, refconfig.version) + urlMap.Set(constant.CLUSTER_KEY, refconfig.Cluster) + urlMap.Set(constant.LOADBALANCE_KEY, refconfig.Loadbalance) + urlMap.Set(constant.RETRIES_KEY, strconv.FormatInt(refconfig.Retries, 10)) + urlMap.Set(constant.GROUP_KEY, refconfig.Group) + urlMap.Set(constant.VERSION_KEY, refconfig.Version) //getty invoke async or sync urlMap.Set(constant.ASYNC_KEY, strconv.FormatBool(refconfig.async)) @@ -98,9 +97,9 @@ func (refconfig *ReferenceConfig) getUrlMap() url.Values { urlMap.Set(constant.OWNER_KEY, consumerConfig.ApplicationConfig.Owner) urlMap.Set(constant.ENVIRONMENT_KEY, consumerConfig.ApplicationConfig.Environment) - for _, v := range refconfig.methods { - urlMap.Set("methods."+v.name+"."+constant.LOADBALANCE_KEY, v.loadbalance) - urlMap.Set("methods."+v.name+"."+constant.RETRIES_KEY, strconv.FormatInt(v.retries, 10)) + for _, v := range refconfig.Methods { + urlMap.Set("methods."+v.Name+"."+constant.LOADBALANCE_KEY, v.Loadbalance) + urlMap.Set("methods."+v.Name+"."+constant.RETRIES_KEY, strconv.FormatInt(v.Retries, 10)) } return urlMap diff --git a/config/support/registry_config.go b/config/support/registry_config.go index 854e9af7297e6fa970b71a97fb5c2fa0b34aab86..2ed5cbeeccc25010f3abb84fc7a1990a05bec496 100644 --- a/config/support/registry_config.go +++ b/config/support/registry_config.go @@ -22,10 +22,10 @@ func loadRegistries(registriesIds []ConfigRegistry, registries []RegistryConfig, var urls []*config.URL for _, registry := range registriesIds { for _, registryConf := range registries { - if registry.string == registryConf.Id { + if string(registry) == registryConf.Id { url, err := config.NewURL(context.TODO(), registryConf.Address, config.WithParams(registryConf.getUrlMap(roleType))) if err != nil { - log.Error("The registry id:%s url is invalid ,and will skip the registry", registryConf.Id) + log.Error("The registry id:%s url is invalid ,and will skip the registry, error: %#v", registryConf.Id, err) } else { urls = append(urls, &url) } diff --git a/config/support/service_config.go b/config/support/service_config.go index 5565bafff60decb8e8a6cbaeba17d508595b5a8c..bb50db7b8ee2a4031eb75457526fe396cb2df599 100644 --- a/config/support/service_config.go +++ b/config/support/service_config.go @@ -20,21 +20,21 @@ import ( type ServiceConfig struct { context context.Context - protocol string //multi protocol support, split by ',' - interfaceName string `required:"true" yaml:"interface" json:"interface,omitempty"` - registries []ConfigRegistry `required:"true" yaml:"registries" json:"registries,omitempty"` - cluster string `default:"failover" yaml:"cluster" json:"cluster,omitempty"` - loadbalance string `default:"random" yaml:"loadbalance" json:"loadbalance,omitempty"` - group string `yaml:"group" json:"group,omitempty"` - version string `yaml:"version" json:"version,omitempty"` - methods []struct { - name string `yaml:"name" json:"name,omitempty"` - retries int64 `yaml:"retries" json:"retries,omitempty"` - loadbalance string `yaml:"loadbalance" json:"loadbalance,omitempty"` - weight int64 `yaml:"weight" json:"weight,omitempty"` + Protocol string `required:"true" yaml:"protocol" json:"protocol,omitempty"`//multi protocol support, split by ',' + InterfaceName string `required:"true" yaml:"interface" json:"interface,omitempty"` + Registries []ConfigRegistry `required:"true" yaml:"registries" json:"registries,omitempty"` + Cluster string `default:"failover" yaml:"cluster" json:"cluster,omitempty"` + Loadbalance string `default:"random" yaml:"loadbalance" json:"loadbalance,omitempty"` + Group string `yaml:"group" json:"group,omitempty"` + Version string `yaml:"version" json:"version,omitempty"` + Methods []struct { + Name string `yaml:"name" json:"name,omitempty"` + Retries int64 `yaml:"retries" json:"retries,omitempty"` + Loadbalance string `yaml:"loadbalance" json:"loadbalance,omitempty"` + Weight int64 `yaml:"weight" json:"weight,omitempty"` } `yaml:"methods" json:"methods,omitempty"` - warmup string `yaml:"warmup" json:"warmup,omitempty"` - retries int64 `yaml:"retries" json:"retries,omitempty"` + Warmup string `yaml:"warmup" json:"warmup,omitempty"` + Retries int64 `yaml:"retries" json:"retries,omitempty"` unexported *atomic.Bool exported *atomic.Bool rpcService config.RPCService @@ -53,35 +53,35 @@ func (srvconfig *ServiceConfig) Export() error { //TODO: config center start here //TODO:delay export - if srvconfig.unexported.Load() { - err := jerrors.Errorf("The service %v has already unexported! ", srvconfig.interfaceName) + if srvconfig.unexported != nil && srvconfig.unexported.Load() { + err := jerrors.Errorf("The service %v has already unexported! ", srvconfig.InterfaceName) log.Error(err.Error()) return err } - if srvconfig.exported.Load() { - log.Warn("The service %v has already exported! ", srvconfig.interfaceName) + if srvconfig.unexported != nil && srvconfig.exported.Load() { + log.Warn("The service %v has already exported! ", srvconfig.InterfaceName) return nil } - regUrls := loadRegistries(srvconfig.registries, providerConfig.Registries, config.PROVIDER) + regUrls := loadRegistries(srvconfig.Registries, providerConfig.Registries, config.PROVIDER) urlMap := srvconfig.getUrlMap() - for _, proto := range loadProtocol(srvconfig.protocol, providerConfig.Protocols) { + for _, proto := range loadProtocol(srvconfig.Protocol, providerConfig.Protocols) { //registry the service reflect - _, err := config.ServiceMap.Register(proto.name, srvconfig.rpcService) + _, err := config.ServiceMap.Register(proto.Name, srvconfig.rpcService) if err != nil { - err := jerrors.Errorf("The service %v export the protocol %v error! Error message is %v .", srvconfig.interfaceName, proto.name, err.Error()) + err := jerrors.Errorf("The service %v export the protocol %v error! Error message is %v .", srvconfig.InterfaceName, proto.Name, err.Error()) log.Error(err.Error()) return err } - contextPath := proto.contextPath + contextPath := proto.ContextPath if contextPath == "" { contextPath = providerConfig.Path } - url := config.NewURLWithOptions(srvconfig.interfaceName, - config.WithProtocol(proto.name), - config.WithIp(proto.ip), - config.WithPort(proto.port), + url := config.NewURLWithOptions(srvconfig.InterfaceName, + config.WithProtocol(proto.Name), + config.WithIp(proto.Ip), + config.WithPort(proto.Port), config.WithPath(contextPath), config.WithParams(urlMap)) @@ -104,12 +104,12 @@ func (srvconfig *ServiceConfig) getUrlMap() url.Values { urlMap := url.Values{} urlMap.Set(constant.TIMESTAMP_KEY, strconv.FormatInt(time.Now().Unix(), 10)) - urlMap.Set(constant.CLUSTER_KEY, srvconfig.cluster) - urlMap.Set(constant.LOADBALANCE_KEY, srvconfig.loadbalance) - urlMap.Set(constant.WARMUP_KEY, srvconfig.warmup) - urlMap.Set(constant.RETRIES_KEY, strconv.FormatInt(srvconfig.retries, 10)) - urlMap.Set(constant.GROUP_KEY, srvconfig.group) - urlMap.Set(constant.VERSION_KEY, srvconfig.version) + urlMap.Set(constant.CLUSTER_KEY, srvconfig.Cluster) + urlMap.Set(constant.LOADBALANCE_KEY, srvconfig.Loadbalance) + urlMap.Set(constant.WARMUP_KEY, srvconfig.Warmup) + urlMap.Set(constant.RETRIES_KEY, strconv.FormatInt(srvconfig.Retries, 10)) + urlMap.Set(constant.GROUP_KEY, srvconfig.Group) + urlMap.Set(constant.VERSION_KEY, srvconfig.Version) //application info urlMap.Set(constant.APPLICATION_KEY, providerConfig.ApplicationConfig.Name) urlMap.Set(constant.ORGANIZATION_KEY, providerConfig.ApplicationConfig.Organization) @@ -119,10 +119,10 @@ func (srvconfig *ServiceConfig) getUrlMap() url.Values { urlMap.Set(constant.OWNER_KEY, providerConfig.ApplicationConfig.Owner) urlMap.Set(constant.ENVIRONMENT_KEY, providerConfig.ApplicationConfig.Environment) - for _, v := range srvconfig.methods { - urlMap.Set("methods."+v.name+"."+constant.LOADBALANCE_KEY, v.loadbalance) - urlMap.Set("methods."+v.name+"."+constant.RETRIES_KEY, strconv.FormatInt(v.retries, 10)) - urlMap.Set("methods."+v.name+"."+constant.WEIGHT_KEY, strconv.FormatInt(v.weight, 10)) + for _, v := range srvconfig.Methods { + urlMap.Set("methods."+v.Name+"."+constant.LOADBALANCE_KEY, v.Loadbalance) + urlMap.Set("methods."+v.Name+"."+constant.RETRIES_KEY, strconv.FormatInt(v.Retries, 10)) + urlMap.Set("methods."+v.Name+"."+constant.WEIGHT_KEY, strconv.FormatInt(v.Weight, 10)) } return urlMap diff --git a/config/url.go b/config/url.go index 8f796cd0ef64ee6102df1abc3857d726b0df7d60..4f2181c3ca03e3ceaecf8fd1c03d65fd07b73857 100644 --- a/config/url.go +++ b/config/url.go @@ -132,6 +132,7 @@ func NewURL(ctx context.Context, urlString string, opts ...option) (URL, error) return s, jerrors.Errorf("url.QueryUnescape(%s), error{%v}", urlString, err) } + rawUrlString = "//"+rawUrlString serviceUrl, err = url.Parse(rawUrlString) if err != nil { return s, jerrors.Errorf("url.Parse(url string{%s}), error{%v}", rawUrlString, err) diff --git a/examples/client_config.go b/examples/client_config.go deleted file mode 100644 index 59b312c281d3cc6ac60284785bd1da30261c6f28..0000000000000000000000000000000000000000 --- a/examples/client_config.go +++ /dev/null @@ -1,121 +0,0 @@ -package examples - -import ( - "fmt" - "io/ioutil" - "os" - "path" - "time" -) - -import ( - "github.com/AlexStocks/goext/log" - log "github.com/AlexStocks/log4go" - jerrors "github.com/juju/errors" - "gopkg.in/yaml.v2" -) - -import ( - "github.com/dubbo/dubbo-go/plugins" - "github.com/dubbo/dubbo-go/registry" - "github.com/dubbo/dubbo-go/registry/zookeeper" -) - -const ( - APP_CONF_FILE = "APP_CONF_FILE" - APP_LOG_CONF_FILE = "APP_LOG_CONF_FILE" -) - -type ( - // Client holds supported types by the multiconfig package - ClientConfig struct { - // pprof - Pprof_Enabled bool `default:"false" yaml:"pprof_enabled" json:"pprof_enabled,omitempty"` - Pprof_Port int `default:"10086" yaml:"pprof_port" json:"pprof_port,omitempty"` - - // client - Connect_Timeout string `default:"100ms" yaml:"connect_timeout" json:"connect_timeout,omitempty"` - ConnectTimeout time.Duration - - Request_Timeout string `yaml:"request_timeout" default:"5s" json:"request_timeout,omitempty"` // 500ms, 1m - RequestTimeout time.Duration - - // codec & selector & transport & registry - Selector string `default:"cache" yaml:"selector" json:"selector,omitempty"` - Selector_TTL string `default:"10m" yaml:"selector_ttl" json:"selector_ttl,omitempty"` - //client load balance algorithm - ClientLoadBalance string `default:"round_robin" yaml:"client_load_balance" json:"client_load_balance,omitempty"` - Registry string `default:"zookeeper" yaml:"registry" json:"registry,omitempty"` - // application - Application_Config registry.ApplicationConfig `yaml:"application_config" json:"application_config,omitempty"` - ZkRegistryConfig zookeeper.ZkRegistryConfig `yaml:"zk_registry_config" json:"zk_registry_config,omitempty"` - // 涓€涓鎴风鍙厑璁镐娇鐢ㄤ竴涓猻ervice鐨勫叾涓竴涓猤roup鍜屽叾涓竴涓獀ersion - ServiceConfigType string `default:"default" yaml:"service_config_type" json:"service_config_type,omitempty"` - ServiceConfigList []registry.ReferenceConfig `yaml:"-"` - ServiceConfigMapList []map[string]string `yaml:"service_list" json:"service_list,omitempty"` - } -) - -func InitClientConfig() *ClientConfig { - - var ( - clientConfig *ClientConfig - confFile string - ) - - // configure - confFile = os.Getenv(APP_CONF_FILE) - if confFile == "" { - panic(fmt.Sprintf("application configure file name is nil")) - return nil // I know it is of no usage. Just Err Protection. - } - if path.Ext(confFile) != ".yml" { - panic(fmt.Sprintf("application configure file name{%v} suffix must be .yml", confFile)) - return nil - } - clientConfig = new(ClientConfig) - - confFileStream, err := ioutil.ReadFile(confFile) - if err != nil { - panic(fmt.Sprintf("ioutil.ReadFile(file:%s) = error:%s", confFile, jerrors.ErrorStack(err))) - return nil - } - err = yaml.Unmarshal(confFileStream, clientConfig) - if err != nil { - panic(fmt.Sprintf("yaml.Unmarshal() = error:%s", jerrors.ErrorStack(err))) - return nil - } - - //鍔ㄦ€佸姞杞絪ervice config - //璁剧疆榛樿ProviderServiceConfig绫� - plugins.SetDefaultServiceConfig(clientConfig.ServiceConfigType) - - for _, service := range clientConfig.ServiceConfigMapList { - svc := plugins.DefaultServiceConfig()() - svc.SetProtocol(service["protocol"]) - svc.SetService(service["service"]) - clientConfig.ServiceConfigList = append(clientConfig.ServiceConfigList, svc) - } - //鍔ㄦ€佸姞杞絪ervice config end - - if clientConfig.ZkRegistryConfig.Timeout, err = time.ParseDuration(clientConfig.ZkRegistryConfig.TimeoutStr); err != nil { - panic(fmt.Sprintf("time.ParseDuration(Registry_Config.Timeout:%#v) = error:%s", clientConfig.ZkRegistryConfig.TimeoutStr, err)) - return nil - } - - gxlog.CInfo("config{%#v}\n", clientConfig) - - // log - confFile = os.Getenv(APP_LOG_CONF_FILE) - if confFile == "" { - panic(fmt.Sprintf("log configure file name is nil")) - return nil - } - if path.Ext(confFile) != ".xml" { - panic(fmt.Sprintf("log configure file name{%v} suffix must be .xml", confFile)) - return nil - } - log.LoadConfiguration(confFile) - - return clientConfig -} diff --git a/examples/jsonrpc/go-server/app/config.go b/examples/jsonrpc/go-server/app/config.go deleted file mode 100644 index 16064fca39871f8acd47061fe64124854d22dadf..0000000000000000000000000000000000000000 --- a/examples/jsonrpc/go-server/app/config.go +++ /dev/null @@ -1,132 +0,0 @@ -package main - -import ( - "fmt" - "io/ioutil" - "os" - "path" - "time" -) - -import ( - "github.com/AlexStocks/goext/log" - log "github.com/AlexStocks/log4go" - jerrors "github.com/juju/errors" - "gopkg.in/yaml.v2" -) - -import ( - "github.com/dubbo/dubbo-go/plugins" - "github.com/dubbo/dubbo-go/registry" - "github.com/dubbo/dubbo-go/registry/zookeeper" - "github.com/dubbo/dubbo-go/server" -) - -const ( - APP_CONF_FILE string = "APP_CONF_FILE" - APP_LOG_CONF_FILE string = "APP_LOG_CONF_FILE" -) - -var ( - conf *ServerConfig -) - -type ( - ServerConfig struct { - // pprof - Pprof_Enabled bool `default:"false" yaml:"pprof_enabled" json:"pprof_enabled,omitempty"` - Pprof_Port int `default:"10086" yaml:"pprof_port" json:"pprof_port,omitempty"` - - // transport & registry - Transport string `default:"http" yaml:"transport" json:"transport,omitempty"` - NetTimeout string `default:"100ms" yaml:"net_timeout" json:"net_timeout,omitempty"` // in ms - netTimeout time.Duration - // application - Application_Config registry.ApplicationConfig `yaml:"application_config" json:"application_config,omitempty"` - // Registry_Address string `default:"192.168.35.3:2181"` - Registry string `default:"zookeeper" yaml:"registry" json:"registry,omitempty"` - ZkRegistryConfig zookeeper.ZkRegistryConfig `yaml:"zk_registry_config" json:"zk_registry_config,omitempty"` - - ServiceConfigType string `default:"default" yaml:"service_config_type" json:"service_config_type,omitempty"` - ServiceConfigList []registry.ProviderServiceConfig `yaml:"-"` - ServiceConfigMapList []map[string]string `yaml:"service_list" json:"service_list,omitempty"` - - ServerConfigList []server.ServerConfig `yaml:"server_list" json:"server_list,omitempty"` - } -) - -func initServerConf() *ServerConfig { - var ( - err error - confFile string - ) - - confFile = os.Getenv(APP_CONF_FILE) - if confFile == "" { - panic(fmt.Sprintf("application configure file name is nil")) - return nil - } - if path.Ext(confFile) != ".yml" { - panic(fmt.Sprintf("application configure file name{%v} suffix must be .yml", confFile)) - return nil - } - - conf = &ServerConfig{} - confFileStream, err := ioutil.ReadFile(confFile) - if err != nil { - panic(fmt.Sprintf("ioutil.ReadFile(file:%s) = error:%s", confFile, jerrors.ErrorStack(err))) - return nil - } - err = yaml.Unmarshal(confFileStream, conf) - - //鍔ㄦ€佸姞杞絪ervice config - //璁剧疆榛樿ProviderServiceConfig绫� - plugins.SetDefaultProviderServiceConfig(conf.ServiceConfigType) - for _, service := range conf.ServiceConfigMapList { - - svc := plugins.DefaultProviderServiceConfig()() - svc.SetProtocol(service["protocol"]) - svc.SetService(service["service"]) - conf.ServiceConfigList = append(conf.ServiceConfigList, svc) - } - //鍔ㄦ€佸姞杞絪ervice config end - if err != nil { - panic(fmt.Sprintf("yaml.Unmarshal() = error:%s", jerrors.ErrorStack(err))) - return nil - } - if conf.netTimeout, err = time.ParseDuration(conf.NetTimeout); err != nil { - panic(fmt.Sprintf("time.ParseDuration(NetTimeout:%#v) = error:%s", conf.NetTimeout, err)) - return nil - } - if conf.ZkRegistryConfig.Timeout, err = time.ParseDuration(conf.ZkRegistryConfig.TimeoutStr); err != nil { - panic(fmt.Sprintf("time.ParseDuration(Registry_Config.Timeout:%#v) = error:%s", - conf.ZkRegistryConfig.TimeoutStr, err)) - return nil - } - - gxlog.CInfo("config{%#v}\n", conf) - - return conf -} - -func configInit() error { - var ( - confFile string - ) - - initServerConf() - - confFile = os.Getenv(APP_LOG_CONF_FILE) - if confFile == "" { - panic(fmt.Sprintf("log configure file name is nil")) - return nil - } - if path.Ext(confFile) != ".xml" { - panic(fmt.Sprintf("log configure file name{%v} suffix must be .xml", confFile)) - return nil - } - - log.LoadConfiguration(confFile) - - return nil -} diff --git a/examples/jsonrpc/go-server/app/server.go b/examples/jsonrpc/go-server/app/server.go index e355e268927051a4e7a0d786194ed5ded5267797..5979044066ecc81cbf38a048c1c9e7afdcc19b06 100644 --- a/examples/jsonrpc/go-server/app/server.go +++ b/examples/jsonrpc/go-server/app/server.go @@ -14,86 +14,46 @@ import ( "github.com/AlexStocks/goext/net" "github.com/AlexStocks/goext/time" log "github.com/AlexStocks/log4go" - jerrors "github.com/juju/errors" ) import ( - "github.com/dubbo/dubbo-go/jsonrpc" - "github.com/dubbo/dubbo-go/plugins" - registry2 "github.com/dubbo/dubbo-go/registry" - "github.com/dubbo/dubbo-go/registry/zookeeper" + "github.com/dubbo/dubbo-go/config/support" + + _ "github.com/dubbo/dubbo-go/protocol/dubbo" + _ "github.com/dubbo/dubbo-go/protocol/jsonrpc" + _ "github.com/dubbo/dubbo-go/registry/protocol" + + _ "github.com/dubbo/dubbo-go/filter/imp" + + _ "github.com/dubbo/dubbo-go/cluster/loadbalance" + _ "github.com/dubbo/dubbo-go/cluster/support" + _ "github.com/dubbo/dubbo-go/registry/zookeeper" ) var ( survivalTimeout = int(3e9) - servo *jsonrpc.Server ) +// they are necessary: +// export CONF_CONSUMER_FILE_PATH="xxx" +// export CONF_PROVIDER_FILE_PATH="xxx" +// export APP_LOG_CONF_FILE="xxx" func main() { - var ( - err error - ) - err = configInit() - if err != nil { - log.Error("configInit() = error{%#v}", err) - return + _, proMap := support.Load() + if proMap == nil { + panic("proMap is nil") } + initProfiling() - servo = initServer() - err = servo.Handle(&UserProvider{}) - if err != nil { - panic(err) - return - } - servo.Start() + //todo initSignal() } -func initServer() *jsonrpc.Server { - var ( - srv *jsonrpc.Server - ) - - if conf == nil { - panic(fmt.Sprintf("conf is nil")) - return nil - } - - // registry - - registry, err := plugins.PluggableRegistries[conf.Registry]( - registry2.WithDubboType(registry2.PROVIDER), - registry2.WithApplicationConf(conf.Application_Config), - zookeeper.WithRegistryConf(conf.ZkRegistryConfig), - ) - - if err != nil || registry == nil { - panic(fmt.Sprintf("fail to init registry.Registy, err:%s", jerrors.ErrorStack(err))) - return nil - } - - // provider - srv = jsonrpc.NewServer( - jsonrpc.Registry(registry), - jsonrpc.ConfList(conf.ServerConfigList), - jsonrpc.ServiceConfList(conf.ServiceConfigList), - ) - - return srv -} - -func uninitServer() { - if servo != nil { - servo.Stop() - } - log.Close() -} - func initProfiling() { - if !conf.Pprof_Enabled { + if !support.GetProviderConfig().Pprof_Enabled { return } const ( @@ -109,7 +69,7 @@ func initProfiling() { if err != nil { panic("cat not get local ip!") } - addr = ip + ":" + strconv.Itoa(conf.Pprof_Port) + addr = ip + ":" + strconv.Itoa(support.GetProviderConfig().Pprof_Port) log.Info("App Profiling startup on address{%v}", addr+PprofPath) go func() { @@ -134,7 +94,7 @@ func initSignal() { }) // 瑕佷箞fastFailTimeout鏃堕棿鍐呮墽琛屽畬姣曚笅闈㈢殑閫昏緫鐒跺悗绋嬪簭閫€鍑猴紝瑕佷箞鎵ц涓婇潰鐨勮秴鏃跺嚱鏁扮▼搴忓己琛岄€€鍑� - uninitServer() + // todo fmt.Println("provider app exit now...") return } diff --git a/examples/jsonrpc/go-server/app/user.go b/examples/jsonrpc/go-server/app/user.go index d8f307549b3d7faab1c9404e01048f7cbd1b4a87..b619caf00baf94ad43140ccdf8f9e518b78b463e 100644 --- a/examples/jsonrpc/go-server/app/user.go +++ b/examples/jsonrpc/go-server/app/user.go @@ -4,6 +4,7 @@ import ( // "encoding/json" "context" "fmt" + "github.com/dubbo/dubbo-go/config/support" "time" ) @@ -14,6 +15,10 @@ import ( type Gender int +func init() { + support.SetProService(new(UserProvider)) +} + const ( MAN = iota WOMAN @@ -134,14 +139,14 @@ func (u *UserProvider) GetUser(ctx context.Context, req *string, rsp *User) erro } */ -func (u *UserProvider) GetUser(ctx context.Context, req []string, rsp *User) error { +func (u *UserProvider) GetUser(ctx context.Context, req []interface{}, rsp *User) error { var ( err error user *User ) gxlog.CInfo("req:%#v", req) - user, err = u.getUser(req[0]) + user, err = u.getUser(req[0].(string)) if err == nil { *rsp = *user gxlog.CInfo("rsp:%#v", rsp) diff --git a/examples/jsonrpc/go-server/app/version.go b/examples/jsonrpc/go-server/app/version.go deleted file mode 100644 index c7552b26e11ec15fd51f3e18905d35d577647cd7..0000000000000000000000000000000000000000 --- a/examples/jsonrpc/go-server/app/version.go +++ /dev/null @@ -1,5 +0,0 @@ -package main - -var ( - Version string = "0.3.1" -) diff --git a/examples/jsonrpc/go-server/profiles/dev/getty.yml b/examples/jsonrpc/go-server/profiles/dev/getty.yml new file mode 100644 index 0000000000000000000000000000000000000000..ae19827a7d0a58dd1573ae5644630ca5f644dfa8 --- /dev/null +++ b/examples/jsonrpc/go-server/profiles/dev/getty.yml @@ -0,0 +1,18 @@ + +session_number: 700 +fail_fast_timeout: "5s" +session_timeout: "20s" +getty_session_param: + compress_encoding: false + tcp_no_delay: true + tcp_keep_alive: true + keep_alive_period: "120s" + tcp_r_buf_size: 262144 + tcp_w_buf_size: 65536 + pkg_rq_size: 1024 + pkg_wq_size: 512 + tcp_read_timeout: "1s" + tcp_write_timeout: "5s" + wait_timeout: "1s" + max_msg_len: 1024 + session_name: "server" diff --git a/examples/jsonrpc/go-server/profiles/dev/server.yml b/examples/jsonrpc/go-server/profiles/dev/server.yml index 2e0abd5151ca8fcc93375f227379e766d034aabf..12340f218ace0d825d5cbdf3756b3fbbf6654b19 100644 --- a/examples/jsonrpc/go-server/profiles/dev/server.yml +++ b/examples/jsonrpc/go-server/profiles/dev/server.yml @@ -8,6 +8,7 @@ pprof_port : 20080 transport : "http" net_timeout : "3s" +path: "" # application config application_config: organization : "ikurento.com" @@ -17,22 +18,42 @@ application_config: owner : "ZX" environment : "dev" -registry: "zookeeper" - -zk_registry_config: - timeout : "3s" - address: - - "127.0.0.1:2181" -service_config_type: "default" -service_list: - - - protocol : "jsonrpc" - # 鐩稿綋浜巇ubbo.xml涓殑interface - service : "com.ikurento.user.UserProvider" - -server_list: - - - ip : "127.0.0.1" - port : 20000 - # 鏈瑂erver鑳藉鎻愪緵鎵€鏈夋敮鎸佸悓鏍风殑Protocol鐨剆ervicelist鐨勬湇鍔� - protocol : "jsonrpc" +registries : +- id: "hangzhouzk" + type: "zookeeper" + timeout : "3s" + address: "127.0.0.1:2181" + username: "" + password: "" + +- id: "shanghaizk" + type: "zookeeper" + timeout : "3s" + address: "127.0.0.1:2182" + username: "" + password: "" + + +services: +- registries: + - "hangzhouzk" + - "shanghaizk" + protocol : "dubbo,jsonrpc" + # 鐩稿綋浜巇ubbo.xml涓殑interface + interface : "com.ikurento.user.UserProvider" + loadbalance: "random" + warmup: "100" + cluster: "failover" + methods: + - name: "GetUser" + retries: 1 + loadbalance: "random" + +protocols: +- name: "dubbo" + ip : "127.0.0.1" + port : 20000 +- name: "jsonrpc" + ip: "127.0.0.1" + port: 20001 + diff --git a/examples/jsonrpc/go-server/profiles/release/getty.yml b/examples/jsonrpc/go-server/profiles/release/getty.yml new file mode 100644 index 0000000000000000000000000000000000000000..ae19827a7d0a58dd1573ae5644630ca5f644dfa8 --- /dev/null +++ b/examples/jsonrpc/go-server/profiles/release/getty.yml @@ -0,0 +1,18 @@ + +session_number: 700 +fail_fast_timeout: "5s" +session_timeout: "20s" +getty_session_param: + compress_encoding: false + tcp_no_delay: true + tcp_keep_alive: true + keep_alive_period: "120s" + tcp_r_buf_size: 262144 + tcp_w_buf_size: 65536 + pkg_rq_size: 1024 + pkg_wq_size: 512 + tcp_read_timeout: "1s" + tcp_write_timeout: "5s" + wait_timeout: "1s" + max_msg_len: 1024 + session_name: "server" diff --git a/examples/jsonrpc/go-server/profiles/release/server.yml b/examples/jsonrpc/go-server/profiles/release/server.yml index ca33e45bccf08d09bc39338132ebfbfb13bd6fdc..ec57f99db9b43058a967aa37f359ee124cc54d26 100644 --- a/examples/jsonrpc/go-server/profiles/release/server.yml +++ b/examples/jsonrpc/go-server/profiles/release/server.yml @@ -8,6 +8,7 @@ pprof_port : 20080 transport : "http" net_timeout : "3s" +path: "" # application config application_config: organization : "ikurento.com" @@ -15,24 +16,44 @@ application_config: module : "dubbogo user-info server" version : "0.0.1" owner : "ZX" - environment : "product" - -registry: "zookeeper" - -zk_registry_config: - timeout : "3s" - address: - - "127.0.0.1:2181" -service_config_type: "default" -service_list: - - - protocol : "jsonrpc" - # 鐩稿綋浜巇ubbo.xml涓殑interface - service : "com.ikurento.user.UserProvider" - -server_list: - - - ip : "127.0.0.1" - port : 20000 - # 鏈瑂erver鑳藉鎻愪緵鎵€鏈夋敮鎸佸悓鏍风殑Protocol鐨剆ervicelist鐨勬湇鍔� - protocol : "jsonrpc" + environment : "pro" + +registries : +- id: "hangzhouzk" + type: "zookeeper" + timeout : "3s" + address: "127.0.0.1:2181" + username: "" + password: "" + +- id: "shanghaizk" + type: "zookeeper" + timeout : "3s" + address: "127.0.0.1:2182" + username: "" + password: "" + + +services: +- registries: + - "hangzhouzk" + - "shanghaizk" + protocol : "dubbo,jsonrpc" + # 鐩稿綋浜巇ubbo.xml涓殑interface + interface : "com.ikurento.user.UserProvider" + loadbalance: "random" + warmup: "100" + cluster: "failover" + methods: + - name: "GetUser" + retries: 1 + loadbalance: "random" + +protocols: +- name: "dubbo" + ip : "127.0.0.1" + port : 20000 +- name: "jsonrpc" + ip: "127.0.0.1" + port: 20001 + diff --git a/examples/jsonrpc/go-server/profiles/test/getty.yml b/examples/jsonrpc/go-server/profiles/test/getty.yml new file mode 100644 index 0000000000000000000000000000000000000000..ae19827a7d0a58dd1573ae5644630ca5f644dfa8 --- /dev/null +++ b/examples/jsonrpc/go-server/profiles/test/getty.yml @@ -0,0 +1,18 @@ + +session_number: 700 +fail_fast_timeout: "5s" +session_timeout: "20s" +getty_session_param: + compress_encoding: false + tcp_no_delay: true + tcp_keep_alive: true + keep_alive_period: "120s" + tcp_r_buf_size: 262144 + tcp_w_buf_size: 65536 + pkg_rq_size: 1024 + pkg_wq_size: 512 + tcp_read_timeout: "1s" + tcp_write_timeout: "5s" + wait_timeout: "1s" + max_msg_len: 1024 + session_name: "server" diff --git a/examples/jsonrpc/go-server/profiles/test/server.yml b/examples/jsonrpc/go-server/profiles/test/server.yml index 0c8be2383a37277713d7702d6b10aa366fedf2fd..509bc2cbb25ad1e66e53b330babc79cbfb65dba6 100644 --- a/examples/jsonrpc/go-server/profiles/test/server.yml +++ b/examples/jsonrpc/go-server/profiles/test/server.yml @@ -8,31 +8,52 @@ pprof_port : 20080 transport : "http" net_timeout : "3s" +path: "" # application config application_config: - organization : "ikurento.com" - name : "BDTService" - module : "dubbogo user-info server" - version : "0.0.1" - owner : "ZX" - environment : "test" - -registry: "zookeeper" - -zk_registry_config: - timeout : "3s" - address: - - "127.0.0.1:2181" -service_config_type: "default" -service_list: - - - protocol : "jsonrpc" - # 鐩稿綋浜巇ubbo.xml涓殑interface - service : "com.ikurento.user.UserProvider" - -server_list: - - - ip : "127.0.0.1" - port : 20000 - # 鏈瑂erver鑳藉鎻愪緵鎵€鏈夋敮鎸佸悓鏍风殑Protocol鐨剆ervicelist鐨勬湇鍔� - protocol : "jsonrpc" + organization : "ikurento.com" + name : "BDTService" + module : "dubbogo user-info server" + version : "0.0.1" + owner : "ZX" + environment : "test" + +registries : +- id: "hangzhouzk" + type: "zookeeper" + timeout : "3s" + address: "127.0.0.1:2181" + username: "" + password: "" + +- id: "shanghaizk" + type: "zookeeper" + timeout : "3s" + address: "127.0.0.1:2182" + username: "" + password: "" + + +services: +- registries: + - "hangzhouzk" + - "shanghaizk" + protocol : "dubbo,jsonrpc" + # 鐩稿綋浜巇ubbo.xml涓殑interface + interface : "com.ikurento.user.UserProvider" + loadbalance: "random" + warmup: "100" + cluster: "failover" + methods: + - name: "GetUser" + retries: 1 + loadbalance: "random" + +protocols: +- name: "dubbo" + ip : "127.0.0.1" + port : 20000 +- name: "jsonrpc" + ip: "127.0.0.1" + port: 20001 + diff --git a/protocol/jsonrpc/http.go b/protocol/jsonrpc/http.go index c7aa1e828427cd00c7fc7b77841d8c2aa7edae3d..0d3c00cfe1d8e79809662de92b887c1d46247464 100644 --- a/protocol/jsonrpc/http.go +++ b/protocol/jsonrpc/http.go @@ -10,7 +10,6 @@ import ( "net/http" "net/url" "os" - "strconv" "strings" "sync/atomic" "time" @@ -98,10 +97,6 @@ func (c *HTTPClient) Call(ctx context.Context, service config.URL, req *Request, httpHeader.Set("Accept", "application/json") reqTimeout := c.options.HTTPTimeout - timeout, err := strconv.ParseInt(service.GetParam(constant.TIMEOUT_KEY,""), 10, 64) - if err == nil && time.Duration(timeout)< reqTimeout { - reqTimeout = time.Duration(timeout) - } if reqTimeout <= 0 { reqTimeout = 1e8 } diff --git a/protocol/jsonrpc/server.go b/protocol/jsonrpc/server.go index 4ca0d6303b66ded3342b05bcf276024a79813c2f..026cd4b1f091b384ac3fe0ed97d03917c3ad8f79 100644 --- a/protocol/jsonrpc/server.go +++ b/protocol/jsonrpc/server.go @@ -4,7 +4,6 @@ import ( "bufio" "bytes" "context" - "github.com/dubbo/dubbo-go/common/constant" "io" "io/ioutil" "net" @@ -22,6 +21,7 @@ import ( ) import ( + "github.com/dubbo/dubbo-go/common/constant" "github.com/dubbo/dubbo-go/config" "github.com/dubbo/dubbo-go/protocol" ) diff --git a/registry/directory/directory.go b/registry/directory/directory.go index 7701a622d1ebbcd18ecc0e6ead4b8c12bedca5ad..4e1967f5048c43f50ea6a8db3983596ba80644ce 100644 --- a/registry/directory/directory.go +++ b/registry/directory/directory.go @@ -18,9 +18,10 @@ import ( "github.com/dubbo/dubbo-go/protocol" "github.com/dubbo/dubbo-go/protocol/protocolwrapper" "github.com/dubbo/dubbo-go/registry" - protocol2 "github.com/dubbo/dubbo-go/registry/protocol" ) +const RegistryConnDelay = 3 + type Options struct { serviceTTL time.Duration } @@ -77,7 +78,7 @@ func (dir *RegistryDirectory) Subscribe(url config.URL) { return } log.Warn("getListener() = err:%s", jerrors.ErrorStack(err)) - time.Sleep(time.Duration(protocol2.RegistryConnDelay) * time.Second) + time.Sleep(time.Duration(RegistryConnDelay) * time.Second) continue } @@ -85,7 +86,7 @@ func (dir *RegistryDirectory) Subscribe(url config.URL) { if serviceEvent, err := listener.Next(); err != nil { log.Warn("Selector.watch() = error{%v}", jerrors.ErrorStack(err)) listener.Close() - time.Sleep(time.Duration(protocol2.RegistryConnDelay) * time.Second) + time.Sleep(time.Duration(RegistryConnDelay) * time.Second) return } else { go dir.update(serviceEvent) diff --git a/registry/protocol/protocol.go b/registry/protocol/protocol.go index 6281156f4c24f526af60eb7ec663ea3e8d88757b..bf8c908b3ca0b9d6c6b4314ed600f9e508e878fa 100644 --- a/registry/protocol/protocol.go +++ b/registry/protocol/protocol.go @@ -1,7 +1,6 @@ package protocol import ( - "github.com/dubbo/dubbo-go/protocol/protocolwrapper" "sync" ) @@ -14,12 +13,11 @@ import ( "github.com/dubbo/dubbo-go/common/extension" "github.com/dubbo/dubbo-go/config" "github.com/dubbo/dubbo-go/protocol" + "github.com/dubbo/dubbo-go/protocol/protocolwrapper" "github.com/dubbo/dubbo-go/registry" directory2 "github.com/dubbo/dubbo-go/registry/directory" ) -const RegistryConnDelay = 3 - var registryProtocol *RegistryProtocol type RegistryProtocol struct { @@ -119,7 +117,7 @@ func newWrappedInvoker(invoker protocol.Invoker, url config.URL) *wrappedInvoker return &wrappedInvoker{ invoker: invoker, url: url, - BaseInvoker: *protocol.NewBaseInvoker(nil), + BaseInvoker: *protocol.NewBaseInvoker(config.URL{}), } } func (ivk *wrappedInvoker) GetUrl() config.URL { diff --git a/registry/zookeeper/listener.go b/registry/zookeeper/listener.go index d8b7d1fae62ddc7925288b1fe8141d38aa63e00b..2ad96a3a61d702eebb0739ecd6c854df967eaf95 100644 --- a/registry/zookeeper/listener.go +++ b/registry/zookeeper/listener.go @@ -114,7 +114,7 @@ func (l *zkEventListener) handleZkNodeEvent(zkPath string, children []string, co newNode = path.Join(zkPath, n) log.Info("add zkNode{%s}", newNode) //context.TODO - &serviceURL, err = config.NewURL(context.TODO(), n) + serviceURL, err = config.NewURL(context.TODO(), n) if err != nil { log.Error("NewURL(%s) = error{%v}", n, jerrors.ErrorStack(err)) continue @@ -145,7 +145,7 @@ func (l *zkEventListener) handleZkNodeEvent(zkPath string, children []string, co oldNode = path.Join(zkPath, n) log.Warn("delete zkPath{%s}", oldNode) - &serviceURL, err = config.NewURL(context.TODO(), n) + serviceURL, err = config.NewURL(context.TODO(), n) if !conf.URLEqual(serviceURL) { log.Warn("serviceURL{%s} has been deleted is not compatible with SubURL{%#v}", serviceURL, conf) continue @@ -257,7 +257,7 @@ func (l *zkEventListener) listenServiceEvent(conf config.URL) { for _, c := range children { - &serviceURL, err = config.NewURL(context.TODO(), c) + serviceURL, err = config.NewURL(context.TODO(), c) if err != nil { log.Error("NewURL(r{%s}) = error{%v}", c, err) continue