Properly hanlde gRPC session timeout
This commit is contained in:
parent
7644aa4342
commit
02585823fc
@ -19,7 +19,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
|||||||
import com.google.common.io.Resources;
|
import com.google.common.io.Resources;
|
||||||
import com.google.common.util.concurrent.FutureCallback;
|
import com.google.common.util.concurrent.FutureCallback;
|
||||||
import io.grpc.Server;
|
import io.grpc.Server;
|
||||||
import io.grpc.ServerBuilder;
|
import io.grpc.netty.NettyServerBuilder;
|
||||||
import io.grpc.stub.StreamObserver;
|
import io.grpc.stub.StreamObserver;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
@ -49,6 +49,7 @@ import java.util.Map;
|
|||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@ -68,6 +69,8 @@ public class EdgeGrpcService extends EdgeRpcServiceGrpc.EdgeRpcServiceImplBase i
|
|||||||
private String privateKeyResource;
|
private String privateKeyResource;
|
||||||
@Value("${edges.state.persistToTelemetry:false}")
|
@Value("${edges.state.persistToTelemetry:false}")
|
||||||
private boolean persistToTelemetry;
|
private boolean persistToTelemetry;
|
||||||
|
@Value("${edges.rpc.client_max_keep_alive_time_sec}")
|
||||||
|
private int clientMaxKeepAliveTimeSec;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private EdgeContextComponent ctx;
|
private EdgeContextComponent ctx;
|
||||||
@ -82,7 +85,9 @@ public class EdgeGrpcService extends EdgeRpcServiceGrpc.EdgeRpcServiceImplBase i
|
|||||||
@PostConstruct
|
@PostConstruct
|
||||||
public void init() {
|
public void init() {
|
||||||
log.info("Initializing Edge RPC service!");
|
log.info("Initializing Edge RPC service!");
|
||||||
ServerBuilder builder = ServerBuilder.forPort(rpcPort).addService(this);
|
NettyServerBuilder builder = NettyServerBuilder.forPort(rpcPort)
|
||||||
|
.permitKeepAliveTime(clientMaxKeepAliveTimeSec, TimeUnit.SECONDS)
|
||||||
|
.addService(this);
|
||||||
if (sslEnabled) {
|
if (sslEnabled) {
|
||||||
try {
|
try {
|
||||||
File certFile = new File(Resources.getResource(certFileResource).toURI());
|
File certFile = new File(Resources.getResource(certFileResource).toURI());
|
||||||
|
|||||||
@ -590,6 +590,7 @@ edges:
|
|||||||
rpc:
|
rpc:
|
||||||
enabled: "${EDGES_RPC_ENABLED:false}"
|
enabled: "${EDGES_RPC_ENABLED:false}"
|
||||||
port: "${EDGES_RPC_PORT:7070}"
|
port: "${EDGES_RPC_PORT:7070}"
|
||||||
|
client_max_keep_alive_time_sec: "${EDGES_RPC_CLIENT_MAX_KEEP_ALIVE_TIME_SEC:300}"
|
||||||
ssl:
|
ssl:
|
||||||
# Enable/disable SSL support
|
# Enable/disable SSL support
|
||||||
enabled: "${EDGES_RPC_SSL_ENABLED:false}"
|
enabled: "${EDGES_RPC_SSL_ENABLED:false}"
|
||||||
|
|||||||
@ -55,6 +55,8 @@ public class EdgeGrpcClient implements EdgeRpcClient {
|
|||||||
private int rpcPort;
|
private int rpcPort;
|
||||||
@Value("${cloud.rpc.timeout}")
|
@Value("${cloud.rpc.timeout}")
|
||||||
private int timeoutSecs;
|
private int timeoutSecs;
|
||||||
|
@Value("${cloud.rpc.keep_alive_time_sec}")
|
||||||
|
private int keepAliveTimeSec;
|
||||||
@Value("${cloud.rpc.ssl.enabled}")
|
@Value("${cloud.rpc.ssl.enabled}")
|
||||||
private boolean sslEnabled;
|
private boolean sslEnabled;
|
||||||
@Value("${cloud.rpc.ssl.cert}")
|
@Value("${cloud.rpc.ssl.cert}")
|
||||||
@ -73,7 +75,9 @@ public class EdgeGrpcClient implements EdgeRpcClient {
|
|||||||
Consumer<EdgeConfiguration> onEdgeUpdate,
|
Consumer<EdgeConfiguration> onEdgeUpdate,
|
||||||
Consumer<DownlinkMsg> onDownlink,
|
Consumer<DownlinkMsg> onDownlink,
|
||||||
Consumer<Exception> onError) {
|
Consumer<Exception> onError) {
|
||||||
NettyChannelBuilder builder = NettyChannelBuilder.forAddress(rpcHost, rpcPort).usePlaintext();
|
NettyChannelBuilder builder = NettyChannelBuilder.forAddress(rpcHost, rpcPort)
|
||||||
|
.keepAliveTime(keepAliveTimeSec, TimeUnit.SECONDS)
|
||||||
|
.usePlaintext();
|
||||||
if (sslEnabled) {
|
if (sslEnabled) {
|
||||||
try {
|
try {
|
||||||
builder.sslContext(GrpcSslContexts.forClient().trustManager(new File(Resources.getResource(certResource).toURI())).build());
|
builder.sslContext(GrpcSslContexts.forClient().trustManager(new File(Resources.getResource(certResource).toURI())).build());
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user