Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ISSUE #872] [Java] feat: should add default keepalive for grpc channel #870

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@

public class RpcClientImpl implements RpcClient {
private static final int CONNECT_TIMEOUT_MILLIS = 3 * 1000;
// the grpc server default permitted min keep alive is 5min, so by default we should not less than 5min.
private static final int KEEP_ALIVE_TIME_MILLIS = 300 * 1000;
private static final int KEEP_ALIVE_TIMEOUT_MILLIS = 30 * 1000;
private static final int GRPC_MAX_MESSAGE_SIZE = Integer.MAX_VALUE;

private final ManagedChannel channel;
Expand All @@ -77,6 +80,9 @@ public RpcClientImpl(Endpoints endpoints, boolean sslEnabled) throws SSLExceptio
final NettyChannelBuilder channelBuilder =
NettyChannelBuilder.forTarget(endpoints.getGrpcTarget())
.withOption(ChannelOption.CONNECT_TIMEOUT_MILLIS, CONNECT_TIMEOUT_MILLIS)
.keepAliveTime(KEEP_ALIVE_TIME_MILLIS, TimeUnit.MILLISECONDS)
.keepAliveTimeout(KEEP_ALIVE_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS)
.keepAliveWithoutCalls(true)
.maxInboundMessageSize(GRPC_MAX_MESSAGE_SIZE)
.intercept(LoggingInterceptor.getInstance());

Expand Down