File tree Expand file tree Collapse file tree 5 files changed +62
-0
lines changed
api/src/main/java/com/alipay/sofa/rpc/common
java/com/alipay/sofa/rpc/common/config
resources/com/alipay/sofa/rpc/common
remoting/remoting-triple/src
main/java/com/alipay/sofa/rpc/transport/triple
test/java/com/alipay/sofa/rpc/transport/triple Expand file tree Collapse file tree 5 files changed +62
-0
lines changed Original file line number Diff line number Diff line change @@ -419,6 +419,7 @@ public class RpcOptions {
419
419
* 默认 grpc maxInboundMessageSize大小
420
420
*/
421
421
public static final String TRANSPORT_GRPC_MAX_INBOUND_MESSAGE_SIZE = "transport.grpc.maxInboundMessageSize" ;
422
+
422
423
/**
423
424
* 最大IO的buffer大小
424
425
*/
Original file line number Diff line number Diff line change @@ -140,4 +140,16 @@ public class RpcConfigKeys {
140
140
false ,
141
141
"specify biz thread pool implementation type" ,
142
142
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
+
143
155
}
Original file line number Diff line number Diff line change @@ -273,6 +273,8 @@ PS:大家也看到了,本JSON文档是支持注释的,而标准JSON是不支
273
273
"compress.size.baseline" : 2048 ,
274
274
//Whether the Http2 Cleartext protocol client uses Prior Knowledge to start Http2
275
275
"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 ,
276
278
/*-------------Transport层相关配置结束-------------*/
277
279
278
280
/*
Original file line number Diff line number Diff line change 16
16
*/
17
17
package com .alipay .sofa .rpc .transport .triple ;
18
18
19
+ import com .alipay .sofa .common .config .SofaConfigs ;
19
20
import com .alipay .sofa .rpc .client .ProviderInfo ;
20
21
import com .alipay .sofa .rpc .common .RpcConfigs ;
21
22
import com .alipay .sofa .rpc .common .RpcOptions ;
23
+ import com .alipay .sofa .rpc .common .config .RpcConfigKeys ;
22
24
import com .alipay .sofa .rpc .common .utils .NetUtils ;
23
25
import com .alipay .sofa .rpc .context .RpcInternalContext ;
24
26
import com .alipay .sofa .rpc .context .RpcInvokeContext ;
@@ -78,6 +80,10 @@ public class TripleClientTransport extends ClientTransport {
78
80
79
81
protected final Object lock = new Object ();
80
82
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
+
81
87
/**
82
88
* The constructor
83
89
*
@@ -278,6 +284,12 @@ private ManagedChannel initChannel(ProviderInfo url) {
278
284
builder .disableRetry ();
279
285
builder .intercept (clientHeaderClientInterceptor );
280
286
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
+
281
293
return builder .build ();
282
294
}
283
295
Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments