Skip to content

Commit

Permalink
feat: support triple grpc heart beat (#1432)
Browse files Browse the repository at this point in the history
* feat: support triple grpc heart beat

* fix: key

---------

Co-authored-by: Lo1nt <[email protected]>
  • Loading branch information
Lo1nt and Lo1nt authored Oct 8, 2024
1 parent 29999af commit ab83fc3
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 0 deletions.
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);

}
}

0 comments on commit ab83fc3

Please sign in to comment.