diff --git a/extensions/grpc/runtime/src/main/java/io/quarkus/grpc/runtime/GrpcServerRecorder.java b/extensions/grpc/runtime/src/main/java/io/quarkus/grpc/runtime/GrpcServerRecorder.java index 77b64699480f0..a24224f237a21 100644 --- a/extensions/grpc/runtime/src/main/java/io/quarkus/grpc/runtime/GrpcServerRecorder.java +++ b/extensions/grpc/runtime/src/main/java/io/quarkus/grpc/runtime/GrpcServerRecorder.java @@ -32,6 +32,7 @@ import io.quarkus.arc.Arc; import io.quarkus.grpc.runtime.config.GrpcConfiguration; import io.quarkus.grpc.runtime.config.GrpcServerConfiguration; +import io.quarkus.grpc.runtime.config.GrpcServerNettyConfig; import io.quarkus.grpc.runtime.devmode.GrpcHotReplacementInterceptor; import io.quarkus.grpc.runtime.devmode.GrpcServerReloader; import io.quarkus.grpc.runtime.health.GrpcHealthStorage; @@ -173,6 +174,14 @@ public void run() { }); } + private void applyNettySettings(GrpcServerConfiguration configuration, VertxServerBuilder builder) { + if (configuration.netty != null) { + GrpcServerNettyConfig config = configuration.netty; + config.keepAliveTime.ifPresent(duration -> builder.nettyBuilder() + .keepAliveTime(duration.toNanos(), TimeUnit.NANOSECONDS)); + } + } + private void applyTransportSecurityConfig(GrpcServerConfiguration configuration, VertxServerBuilder builder) { if (configuration.transportSecurity != null) { File cert = configuration.transportSecurity.certificate @@ -267,6 +276,8 @@ public void handle(HttpServerOptions options) { applyTransportSecurityConfig(configuration, builder); + applyNettySettings(configuration, builder); + boolean reflectionServiceEnabled = configuration.enableReflectionService || ProfileManager.getLaunchMode() == LaunchMode.DEVELOPMENT; List definitions = gatherServices(grpcContainer.getServices()); diff --git a/extensions/grpc/runtime/src/main/java/io/quarkus/grpc/runtime/config/GrpcServerConfiguration.java b/extensions/grpc/runtime/src/main/java/io/quarkus/grpc/runtime/config/GrpcServerConfiguration.java index 37f3d6ac6a62b..2c82482214c81 100644 --- a/extensions/grpc/runtime/src/main/java/io/quarkus/grpc/runtime/config/GrpcServerConfiguration.java +++ b/extensions/grpc/runtime/src/main/java/io/quarkus/grpc/runtime/config/GrpcServerConfiguration.java @@ -73,4 +73,10 @@ public class GrpcServerConfiguration { */ @ConfigItem(defaultValue = "1") public int instances; + + /** + * Configures the netty server settings. + */ + @ConfigItem + public GrpcServerNettyConfig netty; } diff --git a/extensions/grpc/runtime/src/main/java/io/quarkus/grpc/runtime/config/GrpcServerNettyConfig.java b/extensions/grpc/runtime/src/main/java/io/quarkus/grpc/runtime/config/GrpcServerNettyConfig.java new file mode 100644 index 0000000000000..dc7c78f36a2f5 --- /dev/null +++ b/extensions/grpc/runtime/src/main/java/io/quarkus/grpc/runtime/config/GrpcServerNettyConfig.java @@ -0,0 +1,20 @@ +package io.quarkus.grpc.runtime.config; + +import java.time.Duration; +import java.util.Optional; + +import io.quarkus.runtime.annotations.ConfigGroup; +import io.quarkus.runtime.annotations.ConfigItem; + +@SuppressWarnings("OptionalUsedAsFieldOrParameterType") +@ConfigGroup +public class GrpcServerNettyConfig { + + /** + * Sets a custom keep-alive duration. This configures the time before sending a `keepalive` ping + * when there is no read activity. + */ + @ConfigItem + public Optional keepAliveTime; + +}