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

GrpcChannelsProperties default scheme ignored / not used

Open kyle-a-wong opened this issue 3 years ago • 3 comments

The problem The GrpcChannelsProperties configuration class has a "defaultScheme" property that is configurable, but nothing is done with this configuration. As per the documentation:

If you don’t define an address it will be guessed:

-  First it will try it with just it’s name (<name>)
-  If you have configured a default scheme it will try that next (<scheme>:/<name>)
-  Then it will use the default scheme of the NameResolver.Factory delegate (See the priorities above)

But this isn't correct. If there is no address configured for a client, then it will try with just its name, which will then use the default scheme of the NameResolver.Factory delegate. The default scheme in GrpcChannelsProperties is never used.

Each of the ChanelFactory implementations have the following code:

        final GrpcChannelProperties properties = getPropertiesFor(name);
        URI address = properties.getAddress();
        if (address == null) {
            address = URI.create(name);
        }

The Solution ideally it would be something like:

    final GrpcChannelProperties channelProperties = getPropertiesFor(name);
    URI address = channelProperties.getAddress();
    if (address == null) {
      String defaultScheme = getProperties().getDefaultScheme();
      if (defaultScheme != null) {
        address = URI.create(defaultScheme + ":///" + name);
      } else {
        address = URI.create(name);
      }
    }
    ...

kyle-a-wong avatar May 02 '22 13:05 kyle-a-wong

Yes, you are right. Contributions are welcome.

ST-DDT avatar May 03 '22 00:05 ST-DDT

I opened a pull requests: https://github.com/yidongnan/grpc-spring-boot-starter/pull/687

kyle-a-wong avatar May 16 '22 15:05 kyle-a-wong

Thanks, I will review it in a few days when I have some more time.

ST-DDT avatar May 16 '22 15:05 ST-DDT

Fixed in #687

ST-DDT avatar Sep 03 '22 08:09 ST-DDT