【发布时间】:2021-09-11 16:30:43
【问题描述】:
第一次调用通常会成功,但随后出现异常消息,如下所示:
io.grpc.StatusRuntimeException:DEADLINE_EXCEEDED:ClientCall 在截止日期后开始:-175.597476157s 从现在开始
为什么秒数是负数?我该如何解决?
我的 grpc 配置:
public class MyAppLibGrpcSenderConfig {
@Value("${grpc.client.host:localhost}")
private String host;
@Value("${grpc.client.port:9090}")
private int port;
@Value("${grpc.client.negotiationType:PLAINTEXT}")
private String negotiationType;
@Value("${grpc.client.deadline:300000}")
private long deadline;
@Autowired
private Tracer tracer;
@Bean
public ManagedChannel managedChannel() {
ManagedChannelBuilder<?> builder = ManagedChannelBuilder.forAddress(host, port);
if ("PLAINTEXT".equals(negotiationType)) {
builder.usePlaintext();
}
return builder.build();
}
@Bean
public TracingClientInterceptor tracingClientInterceptor(Tracer tracer) {
return TracingClientInterceptor
.newBuilder()
.withTracer(this.tracer)
.build();
}
@Bean
public MyAppSenderServiceGrpc.MyAppSenderServiceBlockingStub myAppSenderServiceBlockingStub(
TracingClientInterceptor tracingClientInterceptor,
ManagedChannel managedChannel) {
return MyAppSenderServiceGrpc
.newBlockingStub(tracingClientInterceptor.intercept(managedChannel))
.withDeadlineAfter(deadline, TimeUnit.MILLISECONDS);
}
@Bean
public MyAppCodeLoaderServiceGrpc.MyAppCodeLoaderServiceBlockingStub myAppCodeLoaderServiceBlockingStub(
TracingClientInterceptor tracingClientInterceptor,
ManagedChannel managedChannel) {
return MyAppCodeLoaderServiceGrpc
.newBlockingStub(tracingClientInterceptor.intercept(managedChannel))
.withDeadlineAfter(deadline, TimeUnit.MILLISECONDS);
}
}
客户端代码:
@net.devh.boot.grpc.server.service.GrpcService
public class MyAppEventKafkaSender extends MyAppSenderServiceGrpc.MyAppSenderServiceImplBase {
...
@SneakyThrows
@Override
public void sendMessage(ContextMyAppEventGrpc contextMyAppEventGrpc,
StreamObserver<Empty> responseObserver) {
try {
sendEvent(contextMyAppEventGrpc);
Empty reply = Empty.newBuilder().build();
responseObserver.onNext(reply);
responseObserver.onCompleted();
} catch (Exception e) {
Status status = Status.INTERNAL.withDescription(e.getMessage());
responseObserver.onError(status.asRuntimeException());
}
}
}
【问题讨论】:
标签: spring-boot grpc grpc-java