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

从2.4.0版本升级到 2.13.1版本,配套的spring-cloud-consul 2.1.2版本,无法正确获取grpc服务

Open SpinSi opened this issue 3 years ago • 6 comments

grpc-server-spring-boot-starter 从2.4.0版本升级到 2.13.1版本, 配合使用 spring-cloud-consul-discover 2.1.2版本,无法正确获取grpc服务

grpc-server-spring-boot-starter 2.4.0 通过追踪代码 GrpcDiscoveryClientAutoConfiguration 您使用的ConsulGrpcRegistrationCustomizer 处理grpcPort信息 @Override public void customize(final ConsulRegistration registration) { List<String> tags = registration.getService().getTags(); if (tags == null) { tags = new ArrayList<>(); } final int port = this.grpcServerProperties.getPort(); if (port != -1) { tags.add("gRPC.port=" + port); registration.getService().setTags(tags); } } grpc.port信息写入tags。

但是在 grpc-server-spring-boot-starter 2.13.1 中 您对 GrpcDiscoveryClientAutoConfiguration 做了更新,没有这个操作了,导致 spring-cloud-consul-discover 2.1.2版本,无法正确获取grpc服务。

SpinSi avatar Apr 21 '22 07:04 SpinSi

下面两图是不同版本的注册信息 image image

SpinSi avatar Apr 21 '22 07:04 SpinSi

English


There was an unfortunate breaking change with the cloud providers, that some of them don't support dots in their keys anymore so we had to shift to underscores.

https://github.com/yidongnan/grpc-spring-boot-starter/blob/5e4e5fcfd96a80b157408a0f4c8f2108634d8787/grpc-common-spring-boot/src/main/java/net/devh/boot/grpc/common/util/GrpcUtils.java#L39-L42

We tried to also check the old metadata, but they aren't accessible mostly:

https://github.com/yidongnan/grpc-spring-boot-starter/blob/5e4e5fcfd96a80b157408a0f4c8f2108634d8787/grpc-client-spring-boot-autoconfigure/src/main/java/net/devh/boot/grpc/client/nameresolver/DiscoveryClientNameResolver.java#L168-L189

We now use the metadata across all service discovery providers.

Does that help you?

ST-DDT avatar Apr 21 '22 07:04 ST-DDT

您贴的代码我debug到了,但是客户端通过 spring-cloud-consul-discover 2.1.2 获取不到grpc服务的

SpinSi avatar Apr 21 '22 07:04 SpinSi

Yes, because the keys are no longer the same, so you have to update both the client and the server.

As an alternative, you can overwrite the getGrpcPort method and try to restore the logic to lookup the port from the tags (Since 2.13.0).

ST-DDT avatar Apr 21 '22 07:04 ST-DDT

哥哥做好向下兼容啊!😮‍💨

SpinSi avatar Apr 21 '22 08:04 SpinSi

I'm sorry for the trouble. This is caused by an upstream change. We haven't noticed, that the upstream change would cause additional trouble further downstream. You can potentially fix it by downgrading spring-cloud-consul-discovery.

Here a link to the original issue: https://github.com/yidongnan/grpc-spring-boot-starter/issues/495

spring.cloud.consul.discovery.metadata.gRPC.port=9090

Invalid Service Meta: Couldn't load metadata pair ('gRPC.port', '9090'): Key contains invalid characters

Reading the link bellow i found this warning:

https://docs.spring.io/spring-cloud-consul/docs/current/reference/html/index.html#generated-metadata ...Older versions of Spring Cloud Consul populated the ServiceInstance.getMetadata() method from Spring Cloud Commons by parsing the spring.cloud.consul.discovery.tags property. This is no longer supported, please migrate to using the spring.cloud.consul.discovery.metadata map....

ST-DDT avatar Apr 21 '22 08:04 ST-DDT