Skip to content

Commit

Permalink
Merge pull request #14957 from michalszynkiewicz/spoud/feat/grpc-nett…
Browse files Browse the repository at this point in the history
…y-keep-alive-time

Add grpc netty keep-alive-time configuration option
gsmet authored Feb 12, 2021
2 parents 9046f48 + 619dae7 commit 81b9cd2
Showing 3 changed files with 37 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -35,6 +35,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;
@@ -192,6 +193,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
@@ -302,6 +311,8 @@ public void handle(HttpServerOptions options) {

applyTransportSecurityConfig(configuration, builder);

applyNettySettings(configuration, builder);

boolean reflectionServiceEnabled = configuration.enableReflectionService
|| ProfileManager.getLaunchMode() == LaunchMode.DEVELOPMENT;
List<GrpcServiceDefinition> toBeRegistered = collectServiceDefinitions(grpcContainer.getServices());
Original file line number Diff line number Diff line change
@@ -79,4 +79,10 @@ public class GrpcServerConfiguration {
*/
@ConfigItem(defaultValue = "1")
public int instances;

/**
* Configures the netty server settings.
*/
@ConfigItem
public GrpcServerNettyConfig netty;
}
Original file line number Diff line number Diff line change
@@ -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<Duration> keepAliveTime;

}

0 comments on commit 81b9cd2

Please sign in to comment.