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

Support to Spring 6

Open lgklein opened this issue 3 years ago • 22 comments
trafficstars

In November we will have the release of spring framework 6.0 and Boot 3.0, both with AOT integrated. Would be very nice to have support for this new version.

lgklein avatar Oct 26 '22 14:10 lgklein

We got a PR for the new auto config files used in Spring Boot 3 #775. Is there anything else we "need" to support/for compatibility?

As for AOT integration it is tracked here: https://github.com/yidongnan/grpc-spring-boot-starter/issues/577 Without external help, I won't have a release ready at that time.

ST-DDT avatar Oct 26 '22 16:10 ST-DDT

The change in #775 works for me. AOT also works fine, but there's a missing hint for netty (I will try and get it added to the metadata catalog) and you have to use the non-shaded grpc jars. Sample here: https://github.com/dsyer/native-grpc.

dsyer avatar Dec 08 '22 13:12 dsyer

Hello @dsyer and @ST-DDT tks for your responses! With both yours examples i was able to make the server works (even with the netty-shaddy... not too much trouble with that), but the clients annotated with @GrpcClient(value="xpto") is always null... Maybe you guys have a example of the client too? (I put all autoconfiguration on the imports file likme ST-DDT point)

lgklein avatar Dec 16 '22 20:12 lgklein

If anyone need it too, for make netty-shaded works, i only need to put this dependency com.google.cloud:native-image-suporte:0.14.1 on pom and set the build args with: --initialize-at-run-time=io.grpc.netty.shaded.io.netty.internal.tcnative.CertificateCompressionAlgo

lgklein avatar Dec 16 '22 20:12 lgklein

There is a client in the test in my PR: https://github.com/oracle/graalvm-reachability-metadata/pull/148 (see metadata/io.grpc/grpc-netty/1.51.0/reflect-config.json).

dsyer avatar Dec 16 '22 21:12 dsyer

Tks for the example @dsyer, but saddly this is not enough... I was abble to make it work, but this is not out of the box:

The problem is that all attribute annotated with @GrpcClient is always null. Debbuing the GrpcClientBeanPostProcessor class, i notice that the field was never there. Example:

In a class ContratosClienteClient: @Service public class ContratosClienteClient { @GrpcClient(value = "xxxx") ContratosClienteBlockingStub stubListaContratos; @Autowired private DetalhesContratoMapper mapper;

The method GrpcClientBeanPostProcessor.processFields only bring me the "mapper" attribute...

Looking in the reflect-config.json that the spring generate, we have this:

{ "name": "xxxx.xxxx.xxxx.ContratosClienteClient", "fields": [ { "name": "mapper" } ], "queriedMethods": [ { "name": "<init>", "parameterTypes": [ ] } ] }

So, to be abble to make this works i was obligated to create another config: { "name" : "xxxx.xxxx.xxxx.ContratosClienteClient", "allDeclaredConstructors" : true, "allPublicConstructors" : true, "allDeclaredMethods" : true, "allPublicMethods" : true, "allPublicFields" : true, "allDeclaredFields" : true, "methods" : [ { "name" : "<init>", "parameterTypes" : [ ] } ] }

This work around is really simple in the end, but probably only the autoconfiguration put in .imports is not enough for spring boot 3.0 AOT. This problem doens't happen in JIT formatt, only in AOT.

@ST-DDT FYK.

lgklein avatar Dec 21 '22 11:12 lgklein

This work around is really simple in the end, but probably only the autoconfiguration put in .imports is not enough for spring boot 3.0 AOT. This problem doens't happen in JIT formatt, only in AOT.

Yeah, I know. I hope that I can convince (and potentially PR) protobuf/grpc to generate the required configs automatically for their part, so we only have to check our parts here.

ST-DDT avatar Dec 21 '22 11:12 ST-DDT

There is one more incompatibility with Spring 6

SocketUtils class has been removed from Spring 6 (https://github.com/spring-projects/spring-framework/issues/28054) which is still used in net.devh.boot.grpc.server.config.GrpcServerProperties class.

Is there any plans to replace SocketUtils?

chaitanya87 avatar Jan 19 '23 11:01 chaitanya87

I would open a separate issue about that if I were you.

dsyer avatar Jan 19 '23 11:01 dsyer

We also need #829 and #835. I think with #826 that will make everything pretty usable in Spring Boot 3.

dsyer avatar Apr 03 '23 05:04 dsyer

Any ETA on support for Spring 6?

marcindabrowski avatar May 16 '23 08:05 marcindabrowski

It works pretty well already actually, but those issues I mentioned above would need to be addressed to bring absolutely everything up to date.

dsyer avatar May 16 '23 09:05 dsyer

I can confirm, it basically works with some minor issues.

genuss avatar May 16 '23 17:05 genuss

Can some of you point me to an example of application based on Spring Boot 3 using the grpc-spring-boot-starter (2.14.0.RELEASE)?

SilviyaPBrayanova avatar May 17 '23 07:05 SilviyaPBrayanova

There's a small sample in my fork: https://github.com/dsyer/grpc-spring-boot-starter/tree/springboot3. Also a standalone one at https://github.com/dsyer/native-grpc (linked to above in a comment already).

dsyer avatar May 17 '23 09:05 dsyer

@SilviyaPBrayanova I suggest you look and test everything that was said in this topic, the @dsyer examples really work in very simple scenarios, depending on what you are doing there, some other configurations will be necessary... But nothing that is not simple to do.

lgklein avatar May 17 '23 09:05 lgklein

After adding org.springframework.boot.autoconfigure.AutoConfiguration.imports, the net.devh.boot.grpc.server.autoconfigure.GrpcMetadataZookeeperConfiguration is not initialized properly, resulting in missing grpc port information in the Metadata registered to nacos. What should I do about this problem? @ST-DDT @dsyer @yidongnan

gebizhuxiaowang avatar May 30 '23 08:05 gebizhuxiaowang

Did you copy the AutoConfiguration.imports from master? You might need to provide a few more details about what didn't work.

dsyer avatar May 30 '23 09:05 dsyer

For me, it started to work after adding @ImportAutoConfiguration(GrpcClientAutoConfiguration.class) to my configuration class.

marcindabrowski avatar May 30 '23 14:05 marcindabrowski

AutoConfiguration.imports

net.devh.boot.grpc.client.autoconfigure.GrpcClientAutoConfiguration
net.devh.boot.grpc.client.autoconfigure.GrpcClientMetricAutoConfiguration
net.devh.boot.grpc.client.autoconfigure.GrpcClientHealthAutoConfiguration
net.devh.boot.grpc.client.autoconfigure.GrpcClientSecurityAutoConfiguration
net.devh.boot.grpc.client.autoconfigure.GrpcClientTraceAutoConfiguration
net.devh.boot.grpc.client.autoconfigure.GrpcDiscoveryClientAutoConfiguration

net.devh.boot.grpc.common.autoconfigure.GrpcCommonCodecAutoConfiguration
net.devh.boot.grpc.common.autoconfigure.GrpcCommonTraceAutoConfiguration

net.devh.boot.grpc.server.autoconfigure.GrpcAdviceAutoConfiguration
net.devh.boot.grpc.server.autoconfigure.GrpcHealthServiceAutoConfiguration
net.devh.boot.grpc.server.autoconfigure.GrpcMetadataConsulConfiguration
net.devh.boot.grpc.server.autoconfigure.GrpcMetadataEurekaConfiguration
net.devh.boot.grpc.server.autoconfigure.GrpcMetadataNacosConfiguration
net.devh.boot.grpc.server.autoconfigure.GrpcMetadataZookeeperConfiguration
net.devh.boot.grpc.server.autoconfigure.GrpcReflectionServiceAutoConfiguration
net.devh.boot.grpc.server.autoconfigure.GrpcServerAutoConfiguration
net.devh.boot.grpc.server.autoconfigure.GrpcServerFactoryAutoConfiguration
net.devh.boot.grpc.server.autoconfigure.GrpcServerMetricAutoConfiguration
net.devh.boot.grpc.server.autoconfigure.GrpcServerSecurityAutoConfiguration
net.devh.boot.grpc.server.autoconfigure.GrpcServerTraceAutoConfiguration

The init method in GrpcMetadataNacosConfiguration, which is not executed when the service is started


    @PostConstruct
    public void init() {
        if (this.nacosRegistration != null) {
            int port = this.grpcProperties.getPort();
            if (-1 != port) {
                this.nacosRegistration.getMetadata().put("gRPC_port", Integer.toString(port));
            }
        }

 

@dsyer Later, I will write the address of the project here

gebizhuxiaowang avatar May 31 '23 01:05 gebizhuxiaowang

After adding org.springframework.boot.autoconfigure.AutoConfiguration.imports, the net.devh.boot.grpc.server.autoconfigure.GrpcMetadataZookeeperConfiguration is not initialized properly, resulting in missing grpc port information in the Metadata registered to nacos. What should I do about this problem? @ST-DDT @dsyer @yidongnan

Try adding @EnableConfigurationProperties(value = {GrpcChannelsProperties.class})

For me with Spring Boot 3.1.2 the ConfigurationPropeties of GrpcChannelsProperties didn't load unless I add the above annotation.

MissakaI-ObjectOne avatar Jul 27 '23 12:07 MissakaI-ObjectOne

I don't have any of those problems. Spring will happily call the legacy @PostConstruct, and the @ConfigurationProperties work the same as before. I haven't tried it with all the server metadata options, or with the client autoconfig, so I might be missing something. If no-one wants to post a sample project to reproduce the issue, there doesn't seem much hope that it will be resolved.

dsyer avatar Jul 27 '23 14:07 dsyer