From f141a8c98081ef09d8fa428ed64e3a6dce7223a8 Mon Sep 17 00:00:00 2001 From: "shalk(xiao kun)" Date: Tue, 30 Apr 2024 19:57:39 +0800 Subject: [PATCH] fix miss in-process --- .../GrpcClientAutoConfiguration.java | 43 ++++++++++++++++--- 1 file changed, 37 insertions(+), 6 deletions(-) diff --git a/grpc-client-spring-boot-starter/src/main/java/net/devh/boot/grpc/client/autoconfigure/GrpcClientAutoConfiguration.java b/grpc-client-spring-boot-starter/src/main/java/net/devh/boot/grpc/client/autoconfigure/GrpcClientAutoConfiguration.java index 904ec9357..95e4a75f9 100644 --- a/grpc-client-spring-boot-starter/src/main/java/net/devh/boot/grpc/client/autoconfigure/GrpcClientAutoConfiguration.java +++ b/grpc-client-spring-boot-starter/src/main/java/net/devh/boot/grpc/client/autoconfigure/GrpcClientAutoConfiguration.java @@ -143,13 +143,13 @@ List defaultChannelConfigurers() { return Collections.emptyList(); } - // First try the shaded netty channel factory + // First try the shaded netty channel factory and in process factory @ConditionalOnMissingBean(GrpcChannelFactory.class) @ConditionalOnClass(name = {"io.grpc.netty.shaded.io.netty.channel.Channel", - "io.grpc.netty.shaded.io.grpc.netty.NettyChannelBuilder"}) + "io.grpc.netty.shaded.io.grpc.netty.NettyChannelBuilder", "io.grpc.inprocess.InProcessChannelBuilder"}) @Bean @Lazy - GrpcChannelFactory shadedNettyGrpcChannelFactory( + GrpcChannelFactory inProcessOrShadedNettyGrpcChannelFactory( final GrpcChannelsProperties properties, final GlobalClientInterceptorRegistry globalClientInterceptorRegistry, final List channelConfigurers) { @@ -162,12 +162,13 @@ GrpcChannelFactory shadedNettyGrpcChannelFactory( return new InProcessOrAlternativeChannelFactory(properties, inProcessChannelFactory, channelFactory); } - // Then try the normal netty channel factory + // Then try the normal netty channel factory and in process factory @ConditionalOnMissingBean(GrpcChannelFactory.class) - @ConditionalOnClass(name = {"io.netty.channel.Channel", "io.grpc.netty.NettyChannelBuilder"}) + @ConditionalOnClass(name = {"io.netty.channel.Channel", "io.grpc.netty.NettyChannelBuilder", + "io.grpc.inprocess.InProcessChannelBuilder"}) @Bean @Lazy - GrpcChannelFactory nettyGrpcChannelFactory( + GrpcChannelFactory inProcessOrNettyGrpcChannelFactory( final GrpcChannelsProperties properties, final GlobalClientInterceptorRegistry globalClientInterceptorRegistry, final List channelConfigurers) { @@ -180,8 +181,38 @@ GrpcChannelFactory nettyGrpcChannelFactory( return new InProcessOrAlternativeChannelFactory(properties, inProcessChannelFactory, channelFactory); } + // Then try the shaded netty channel factory + @ConditionalOnMissingBean(GrpcChannelFactory.class) + @ConditionalOnClass(name = {"io.grpc.netty.shaded.io.netty.channel.Channel", + "io.grpc.netty.shaded.io.grpc.netty.NettyChannelBuilder"}) + @Bean + @Lazy + GrpcChannelFactory shadedNettyGrpcChannelFactory( + final GrpcChannelsProperties properties, + final GlobalClientInterceptorRegistry globalClientInterceptorRegistry, + final List channelConfigurers) { + + log.info("Detected grpc-netty-shaded: Creating ShadedNettyChannelFactory"); + return new ShadedNettyChannelFactory(properties, globalClientInterceptorRegistry, channelConfigurers); + } + + // Then try the normal netty channel factory + @ConditionalOnMissingBean(GrpcChannelFactory.class) + @ConditionalOnClass(name = {"io.netty.channel.Channel", "io.grpc.netty.NettyChannelBuilder"}) + @Bean + @Lazy + GrpcChannelFactory nettyGrpcChannelFactory( + final GrpcChannelsProperties properties, + final GlobalClientInterceptorRegistry globalClientInterceptorRegistry, + final List channelConfigurers) { + + log.info("Detected grpc-netty: Creating NettyChannelFactory"); + return new NettyChannelFactory(properties, globalClientInterceptorRegistry, channelConfigurers); + } + // Finally try the in process channel factory @ConditionalOnMissingBean(GrpcChannelFactory.class) + @ConditionalOnClass(name = {"io.grpc.inprocess.InProcessChannelBuilder"}) @Bean @Lazy GrpcChannelFactory inProcessGrpcChannelFactory(