java version: 1.8
spring version: 5.0.6.RELEASE
dgraph4j version: 20.03.0
I have the following configuration for the DGraph client:
@Configuration
public class DGraphConfig {
@Value("${dgraph.url}")
private String url;
@Value("${dgraph.port}")
private int port;
@Value("${dgraph.timeout}")
private int timeout;
public ManagedChannel managedChannel() {
return ManagedChannelBuilder.forAddress(url, port).usePlaintext().build();
}
public ClientInterceptor timeout() {
return new ClientInterceptor() {
@Override
public <ReqT, RespT> ClientCall<ReqT, RespT> interceptCall(
MethodDescriptor<ReqT, RespT> method, CallOptions callOptions, Channel next) {
return next.newCall(method, callOptions.withDeadlineAfter(timeout, TimeUnit.MILLISECONDS));
}
};
}
public DgraphGrpc.DgraphStub stub() {
return DgraphGrpc.newStub(managedChannel()).withInterceptors(timeout());
}
@Bean
@Primary
public DgraphAsyncClient client() {
return new DgraphAsyncClient(stub());
}
}
I’ve set up a timeout of 500ms at first, then 1 second. But the deadline for the first query is always reached. I suspect it’s due to Dgraph4j java client first connect alpha is too slow.
I could set a timeout of 3 seconds, but it doesn’t make much sense, as it’s only slow the first time, subsequent calls are much faster and therefore do not need such a high timeout setting. If the first connect alpha is so slow, is there a way for the deadline to only start counting when all the steps to configure the connection are done?