You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by GitBox <gi...@apache.org> on 2020/07/19 02:05:04 UTC

[GitHub] [dubbo-go] JiaLiangoooo commented on issue #663: registry-consul support pure consumer regist

JiaLiangoooo commented on issue #663:
URL: https://github.com/apache/dubbo-go/issues/663#issuecomment-660572805


   目前并没有好的方案去解决这个问题.  请问有没有更好办法?
   ```
   func registerConsul(wssId string) error {
   	consumerConfig := config.GetConsumerConfig()
   	address := consumerConfig.Registry.Address
   	s := strings.Split(address, ":")
   
   	getRegistry, err := extension.GetRegistry(consumerConfig.Registry.Protocol, newRegistryUrl(s[0], s[1]))
   	if err != nil {
   		return errors.WithMessage(err, "get registry error")
   	}
   
   	var ip string
   	tcp, err := gxnet.ListenOnTCPRandomPort(ip)
   	if err != nil {
   		return errors.WithMessage(err, "listen tcp error")
   	}
   
   	providerUrl := newProviderUrl("localhost", strings.Split(tcp.Addr().String(), ":")[1], wssId, "tcp")
   	err = getRegistry.Register(providerUrl)
   	if err != nil {
   		return errors.WithMessage(err, "register error")
   	}
   
   	// TODO: 这样写有问题,开启一个Go协程去处理, 已经脱离了控制? gxnet是否有提供一个接口可以使用?
   	go func() {
   		logger.Infof("start listen address: %s", tcp.Addr().String())
   		if err := http.ListenAndServe(tcp.Addr().String(), nil); err != nil {
   			logger.Errorf("http listen port:%s error: %v", tcp.Addr().String(), err)
   		}
   	}()
   	return nil
   }
   ```


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org