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

feat: support triple grpc heart beat #1432

Merged
merged 3 commits into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
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 @@ -419,6 +419,7 @@ public class RpcOptions {
* 默认 grpc maxInboundMessageSize大小
*/
public static final String TRANSPORT_GRPC_MAX_INBOUND_MESSAGE_SIZE = "transport.grpc.maxInboundMessageSize";

/**
* 最大IO的buffer大小
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,4 +140,16 @@ public class RpcConfigKeys {
false,
"specify biz thread pool implementation type",
new String[] { "sofa_rpc_server_thread_pool_type" });

/**
* grpc client keep alive interval
*/
public static ConfigKey<Integer> TRIPLE_CLIENT_KEEP_ALIVE_INTERVAL = ConfigKey
.build(
"sofa.rpc.triple.client.keepAlive.interval",
0,
false,
"keep alive interval in second for triple client",
new String[] { "sofa_rpc_triple_client_keepAlive_interval" });

}
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,8 @@ PS:大家也看到了,本JSON文档是支持注释的,而标准JSON是不支
"compress.size.baseline": 2048,
//Whether the Http2 Cleartext protocol client uses Prior Knowledge to start Http2
"transport.client.h2c.usePriorKnowledge": true,
// grpc client keep alive interval, default to 0, no keep alive
"sofa.rpc.triple.client.keepAlive.interval": 0,
/*-------------Transport层相关配置结束-------------*/

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@
*/
package com.alipay.sofa.rpc.transport.triple;

import com.alipay.sofa.common.config.SofaConfigs;
import com.alipay.sofa.rpc.client.ProviderInfo;
import com.alipay.sofa.rpc.common.RpcConfigs;
import com.alipay.sofa.rpc.common.RpcOptions;
import com.alipay.sofa.rpc.common.config.RpcConfigKeys;
import com.alipay.sofa.rpc.common.utils.NetUtils;
import com.alipay.sofa.rpc.context.RpcInternalContext;
import com.alipay.sofa.rpc.context.RpcInvokeContext;
Expand Down Expand Up @@ -78,6 +80,10 @@ public class TripleClientTransport extends ClientTransport {

protected final Object lock = new Object();

protected static int KEEP_ALIVE_INTERVAL = SofaConfigs.getOrCustomDefault(
RpcConfigKeys.TRIPLE_CLIENT_KEEP_ALIVE_INTERVAL,
RpcConfigs.getIntValue(RpcConfigKeys.TRIPLE_CLIENT_KEEP_ALIVE_INTERVAL.getKey()));

/**
* The constructor
*
Expand Down Expand Up @@ -278,6 +284,12 @@ private ManagedChannel initChannel(ProviderInfo url) {
builder.disableRetry();
builder.intercept(clientHeaderClientInterceptor);
builder.maxInboundMessageSize(RpcConfigs.getIntValue(RpcOptions.TRANSPORT_GRPC_MAX_INBOUND_MESSAGE_SIZE));

if (KEEP_ALIVE_INTERVAL > 0) {
builder.keepAliveWithoutCalls(true);
builder.keepAliveTime(KEEP_ALIVE_INTERVAL, TimeUnit.SECONDS);
}

return builder.build();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alipay.sofa.rpc.transport.triple;

import org.junit.Assert;
import org.junit.Test;

/**
*
* @author junyuan
* @version TripleClientTransportTest.java, v 0.1 2024-08-01 17:12 junyuan Exp $
*/
public class TripleClientTransportTest {

@Test
public void testInit() {

Assert.assertEquals(TripleClientTransport.KEEP_ALIVE_INTERVAL, 0);

}
}
Loading