Skip to content

Commit ab83fc3

Browse files
Lo1ntLo1nt
andauthored
feat: support triple grpc heart beat (#1432)
* feat: support triple grpc heart beat * fix: key --------- Co-authored-by: Lo1nt <[email protected]>
1 parent 29999af commit ab83fc3

File tree

5 files changed

+62
-0
lines changed

5 files changed

+62
-0
lines changed

core/api/src/main/java/com/alipay/sofa/rpc/common/RpcOptions.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,7 @@ public class RpcOptions {
419419
* 默认 grpc maxInboundMessageSize大小
420420
*/
421421
public static final String TRANSPORT_GRPC_MAX_INBOUND_MESSAGE_SIZE = "transport.grpc.maxInboundMessageSize";
422+
422423
/**
423424
* 最大IO的buffer大小
424425
*/

core/common/src/main/java/com/alipay/sofa/rpc/common/config/RpcConfigKeys.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,4 +140,16 @@ public class RpcConfigKeys {
140140
false,
141141
"specify biz thread pool implementation type",
142142
new String[] { "sofa_rpc_server_thread_pool_type" });
143+
144+
/**
145+
* grpc client keep alive interval
146+
*/
147+
public static ConfigKey<Integer> TRIPLE_CLIENT_KEEP_ALIVE_INTERVAL = ConfigKey
148+
.build(
149+
"sofa.rpc.triple.client.keepAlive.interval",
150+
0,
151+
false,
152+
"keep alive interval in second for triple client",
153+
new String[] { "sofa_rpc_triple_client_keepAlive_interval" });
154+
143155
}

core/common/src/main/resources/com/alipay/sofa/rpc/common/rpc-config-default.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,8 @@ PS:大家也看到了,本JSON文档是支持注释的,而标准JSON是不支
273273
"compress.size.baseline": 2048,
274274
//Whether the Http2 Cleartext protocol client uses Prior Knowledge to start Http2
275275
"transport.client.h2c.usePriorKnowledge": true,
276+
// grpc client keep alive interval, default to 0, no keep alive
277+
"sofa.rpc.triple.client.keepAlive.interval": 0,
276278
/*-------------Transport层相关配置结束-------------*/
277279

278280
/*

remoting/remoting-triple/src/main/java/com/alipay/sofa/rpc/transport/triple/TripleClientTransport.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,11 @@
1616
*/
1717
package com.alipay.sofa.rpc.transport.triple;
1818

19+
import com.alipay.sofa.common.config.SofaConfigs;
1920
import com.alipay.sofa.rpc.client.ProviderInfo;
2021
import com.alipay.sofa.rpc.common.RpcConfigs;
2122
import com.alipay.sofa.rpc.common.RpcOptions;
23+
import com.alipay.sofa.rpc.common.config.RpcConfigKeys;
2224
import com.alipay.sofa.rpc.common.utils.NetUtils;
2325
import com.alipay.sofa.rpc.context.RpcInternalContext;
2426
import com.alipay.sofa.rpc.context.RpcInvokeContext;
@@ -78,6 +80,10 @@ public class TripleClientTransport extends ClientTransport {
7880

7981
protected final Object lock = new Object();
8082

83+
protected static int KEEP_ALIVE_INTERVAL = SofaConfigs.getOrCustomDefault(
84+
RpcConfigKeys.TRIPLE_CLIENT_KEEP_ALIVE_INTERVAL,
85+
RpcConfigs.getIntValue(RpcConfigKeys.TRIPLE_CLIENT_KEEP_ALIVE_INTERVAL.getKey()));
86+
8187
/**
8288
* The constructor
8389
*
@@ -278,6 +284,12 @@ private ManagedChannel initChannel(ProviderInfo url) {
278284
builder.disableRetry();
279285
builder.intercept(clientHeaderClientInterceptor);
280286
builder.maxInboundMessageSize(RpcConfigs.getIntValue(RpcOptions.TRANSPORT_GRPC_MAX_INBOUND_MESSAGE_SIZE));
287+
288+
if (KEEP_ALIVE_INTERVAL > 0) {
289+
builder.keepAliveWithoutCalls(true);
290+
builder.keepAliveTime(KEEP_ALIVE_INTERVAL, TimeUnit.SECONDS);
291+
}
292+
281293
return builder.build();
282294
}
283295

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package com.alipay.sofa.rpc.transport.triple;
18+
19+
import org.junit.Assert;
20+
import org.junit.Test;
21+
22+
/**
23+
*
24+
* @author junyuan
25+
* @version TripleClientTransportTest.java, v 0.1 2024-08-01 17:12 junyuan Exp $
26+
*/
27+
public class TripleClientTransportTest {
28+
29+
@Test
30+
public void testInit() {
31+
32+
Assert.assertEquals(TripleClientTransport.KEEP_ALIVE_INTERVAL, 0);
33+
34+
}
35+
}

0 commit comments

Comments
 (0)