|
45 | 45 | import io.grpc.netty.GrpcSslContexts;
|
46 | 46 | import io.grpc.netty.NegotiationType;
|
47 | 47 | import io.grpc.netty.NettyChannelBuilder;
|
| 48 | +import io.netty.channel.socket.nio.NioSocketChannel; |
48 | 49 | import io.netty.handler.ssl.SslContext;
|
49 | 50 | import io.netty.handler.ssl.SslContextBuilder;
|
50 | 51 | import io.quarkus.arc.Arc;
|
@@ -208,6 +209,19 @@ public static Channel createChannel(String name, Set<String> perClientIntercepto
|
208 | 209 |
|
209 | 210 | if (builder instanceof NettyChannelBuilder) {
|
210 | 211 | NettyChannelBuilder ncBuilder = (NettyChannelBuilder) builder;
|
| 212 | + // just use the existing Vertx event loop group, if possible |
| 213 | + Vertx vertx = container.instance(Vertx.class).get(); |
| 214 | + // only support NIO for now, since Vertx::transport is not exposed in the API |
| 215 | + if (vertx != null && vertx.isNativeTransportEnabled()) { |
| 216 | + // see https://github.com/eclipse-vertx/vert.x/pull/5292 |
| 217 | + boolean reuseNettyAllocators = Boolean.getBoolean("vertx.reuseNettyAllocators"); |
| 218 | + if (reuseNettyAllocators) { |
| 219 | + // let Netty Grpc to re-use the default Netty allocator as well |
| 220 | + System.setProperty("io.grpc.netty.useCustomAllocator", "false"); |
| 221 | + } |
| 222 | + ncBuilder = ncBuilder.eventLoopGroup(vertx.nettyEventLoopGroup()) |
| 223 | + .channelType(NioSocketChannel.class); |
| 224 | + } |
211 | 225 | builder = ncBuilder
|
212 | 226 | // clients are intercepted using the IOThreadClientInterceptor interceptor which will decide on which
|
213 | 227 | // thread the messages should be processed.
|
|
0 commit comments