@PostConstruct
    public void init() {
        if (zookeeperRegistration != null) {
            final int port = grpcServerProperties.getPort();
            zookeeperRegistration.setPort(0);
            if (GrpcUtils.INTER_PROCESS_DISABLE != port) {
                zookeeperRegistration.getServiceInstance().getPayload().getMetadata()
                        .put(GrpcUtils.CLOUD_DISCOVERY_METADATA_PORT, Integer.toString(port));
            }
        }
    }
Configuration class that configures the required beans for grpc discovery via Zookeeper.

@author zhaochunlin (946599275@gmail.com)
grpc-server-spring-boot-starter/src/main/java/net/devh/boot/grpc/server/autoconfigure/GrpcMetadataZookeeperConfiguration.java