apache / dubbo-go

Go Implementation For Apache Dubbo .
https://dubbo.apache.org/
Apache License 2.0
4.74k stars 929 forks source link

Multi Protocols doesn't work on Nacos #2581

Open mark4z opened 10 months ago

mark4z commented 10 months ago

Environment

Issue description

nacos-go-sdkv2.0 changed the semantics of namingclient.RegisterInstance, resulting in each RegisterInstance() overwriting the entire nacos service instead of appending an Instance.

I think this is an unreasonably breaking change of nacos-go-sdk, and perhaps nacos-go-sdk rather than dubbogo should be the one to fix it.

  protocols:
    dubbo:
      name: dubbo
      port: 20000
    tri:
      name: tri
      port: 20001
// Register will register the service @url to its nacos registry center.
func (nr *nacosRegistry) Register(url *common.URL) error {
    start := time.Now()
    serviceName := getServiceName(url)
    groupName := nr.URL.GetParam(constant.NacosGroupKey, defaultGroup)
    param := createRegisterParam(url, serviceName, groupName)
    logger.Infof("[Nacos Registry] Registry instance with param = %+v", param)
    isRegistry, err := nr.namingClient.Client().RegisterInstance(param)
    metrics.Publish(metricsRegistry.NewRegisterEvent(err == nil && isRegistry, start))
    if err != nil {
        return err
    }
    if !isRegistry {
        return perrors.New("registry [" + serviceName + "] to  nacos failed")
    }
    nr.registryUrls = append(nr.registryUrls, url)
    return nil
}

image

Logs

Click me to check logs ``` Copy logs to here. ```
chickenlj commented 8 months ago

There's another API in Nacos 2.x, something like batchRegister to register all protocol instances at once. I think dubbo-go can try to support this change in Nacos 2.x.