grpc-spring icon indicating copy to clipboard operation
grpc-spring copied to clipboard

nacos服务发现是不受支持的

Open yl-yue opened this issue 3 years ago • 8 comments

问题描述

  • nacos作为注册中心,服务发现是不受支持的,不论是2.x还是1.4.x都是不受支持的
  • nacos作为配置中心,获取配置与更新配置没有问题

接入nacos的测试过程

我是HTTP技术栈转到grpc的,已经习惯了springcloudalibaba,所以期望使用nacos作为注册与配置中心,但在测试过程中我发现nacos的注册能力是不受支持的,我尝试过很多种方式,试图使用服务注册与发现的能力,如下:

  • 建立grpc-spring-boot-starter的空项目来测试
  • 切换grpc-spring-boot-starter各版本来测试
  • 切换nacos版本测试
  • 切换spring-boot版本测试
  • 切换nacos端口测试
  • 调试配置

我尝试了各种方式,发现nacos服务发现的能力都是不受支持的,在nacos服务列表中根本看不到相关服务,进行grpc调用时也报找不到服务。

我查看了grpc-spring-boot-starter相关的所有文档,反复确认了官方的demo,也反复研究了nacos的官方文档,并结合之前http技术栈的经验,但无一例外都没能让nacos支持grpc服务发现的能力。

我的环境

  • java11
  • nacos1.4.x,nacos2.x
  • grpc-spring-boot-starter2.x

为全面接入nacos,在空闲时我将尝试为此提供一个PR

不知是否有相关思路或建议,避免我闭门造车。

yl-yue avatar Jan 11 '22 09:01 yl-yue

English translation


The grpc service is registered via the http service metadata. See also GrpcMetadataNacosConfiguration and DiscoveryClientNameResolver Unfortunately there is no way to generically register a service in spring-cloud's service discovery api.

ST-DDT avatar Jan 11 '22 09:01 ST-DDT

@ST-DDT Does that mean that the current support for NACOS is limited to configuration centers and service registration and discovery is not supported.

Can we use nacOS service registration and discovery capabilities by iterating grPC-spring-boot-starter

yl-yue avatar Jan 11 '22 09:01 yl-yue

Does that mean that the current support for NACOS is limited to configuration centers and service registration and discovery is not supported.

Yes, with the exception of metadata based service discovery.

Can we use nacOS service registration and discovery capabilities by iterating grPC-spring-boot-starter

Not sure what you are referring to. If there is a low maintainance way of registering services, then we can of course add it.

For future reference, if you are not familiar with english write in chinese and let me translate it myself/with google in order to not loose the original intention (Because I have to translate it to my native/brain language afterwards).

ST-DDT avatar Jan 11 '22 09:01 ST-DDT

See also https://github.com/spring-cloud/spring-cloud-commons/issues/1058

ST-DDT avatar Jan 11 '22 10:01 ST-DDT

我好像理解你说的意思了,ConsulEureka是支持服务发现的,因为这两个注册中心是基于通用的metadata实现的能力,而nacos不是(或者说nacos的grpc方案不是)。

不过我看了nacos的api后,发现grpc-spring-boot-starter可以扩展metadata来兼容nacos,不过以这种方式实现的话,以后我们也得考虑兼容性问题,所以你在 spring-cloud/spring-cloud-commons#1058 中提到的解决方案是最优雅的实现

但在 spring-cloud/spring-cloud-commons#1058 方案实现之前,我也会尝试使用扩展metadata的方式来兼容nacos,便于问题能快速解决。

yl-yue avatar Jan 11 '22 11:01 yl-yue

但在 spring-cloud/spring-cloud-commons#1058 方案实现之前,我也会尝试使用扩展metadata的方式来兼容nacos,便于问题能快速解决。

Are you referring to GrpcMetadataNacosConfiguration or something else? If you are referring to a custom nacos service registration, then you don't need any specific metadata, as there is a fallback to the service port if there are no grpc port metadata.

ST-DDT avatar Jan 11 '22 11:01 ST-DDT

You can try the current nacos service discovery support using the following example script: https://github.com/yidongnan/grpc-spring-boot-starter/blob/master/testExamples.sh#L220

ST-DDT avatar Jan 11 '22 11:01 ST-DDT

好的我研究下,感谢解惑,我将尝试解决我所遇到的问题,如果问题能够得到解决,我将为此提交一个pr

yl-yue avatar Jan 11 '22 12:01 yl-yue