Skip to content

Commit

Permalink
Merge pull request #46198 from franz1981/grpc_netty_client
Browse files Browse the repository at this point in the history
Grpc netty client improvements
  • Loading branch information
geoand authored Mar 10, 2025
2 parents 58ff745 + bf12ff2 commit d3a8d95
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ public interface GrpcClientConfiguration {
@WithDefault("false")
boolean useQuarkusGrpcClient();

/**
* Use Vert.x event loop(s) for gRPC client, if it's using the previous Java gRPC support.
*/
@WithDefault("true")
boolean useVertxEventLoop();

/**
* Configure XDS usage, if enabled.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import io.grpc.netty.GrpcSslContexts;
import io.grpc.netty.NegotiationType;
import io.grpc.netty.NettyChannelBuilder;
import io.netty.channel.socket.nio.NioSocketChannel;
import io.netty.handler.ssl.SslContext;
import io.netty.handler.ssl.SslContextBuilder;
import io.quarkus.arc.Arc;
Expand Down Expand Up @@ -206,8 +207,21 @@ public static Channel createChannel(String name, Set<String> perClientIntercepto
builder.defaultServiceConfig(map);
}

if (builder instanceof NettyChannelBuilder) {
if (config.useVertxEventLoop() && builder instanceof NettyChannelBuilder) {
NettyChannelBuilder ncBuilder = (NettyChannelBuilder) builder;
// just use the existing Vertx event loop group, if possible
Vertx vertx = container.instance(Vertx.class).get();
// only support NIO for now, since Vertx::transport is not exposed in the API
if (vertx != null && vertx.isNativeTransportEnabled()) {
// see https://github.com/eclipse-vertx/vert.x/pull/5292
boolean reuseNettyAllocators = Boolean.getBoolean("vertx.reuseNettyAllocators");
if (reuseNettyAllocators) {
// let Netty Grpc to re-use the default Netty allocator as well
System.setProperty("io.grpc.netty.useCustomAllocator", "false");
}
ncBuilder = ncBuilder.eventLoopGroup(vertx.nettyEventLoopGroup())
.channelType(NioSocketChannel.class);
}
builder = ncBuilder
// clients are intercepted using the IOThreadClientInterceptor interceptor which will decide on which
// thread the messages should be processed.
Expand Down Expand Up @@ -395,6 +409,11 @@ public boolean useQuarkusGrpcClient() {
return false;
}

@Override
public boolean useVertxEventLoop() {
return true;
}

@Override
public ClientXds xds() {
return null;
Expand Down

0 comments on commit d3a8d95

Please sign in to comment.