grpc-spring
grpc-spring copied to clipboard
Support to Spring 6
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.
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.
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.
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)
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
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).
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.
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.
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?
I would open a separate issue about that if I were you.
We also need #829 and #835. I think with #826 that will make everything pretty usable in Spring Boot 3.
Any ETA on support for Spring 6?
It works pretty well already actually, but those issues I mentioned above would need to be addressed to bring absolutely everything up to date.
I can confirm, it basically works with some minor issues.
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)?
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).
@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.
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
Did you copy the AutoConfiguration.imports from master? You might need to provide a few more details about what didn't work.
For me, it started to work after adding @ImportAutoConfiguration(GrpcClientAutoConfiguration.class) to my configuration class.
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
After adding
org.springframework.boot.autoconfigure.AutoConfiguration.imports, thenet.devh.boot.grpc.server.autoconfigure.GrpcMetadataZookeeperConfigurationis 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.
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.