回调读取 header 数据的方法卡住了。使用 Grpc JAVA
Call back method to read header data stuck. Using Grpc JAVA
我正在使用 Protoc 3.0 并编写了使用 java 读取 GRPC 流数据的回调方法。
@Override
public <ReqT, RespT> ClientCall<ReqT, RespT> interceptCall(
final MethodDescriptor<ReqT, RespT> method, CallOptions callOptions, Channel next) {
return new ForwardingClientCall.SimpleForwardingClientCall<ReqT, RespT>(
next.newCall(method, callOptions)) {
@Override
public void start(Listener<RespT> responseListener, Metadata headers) {
ClientCall.Listener<RespT> listener = new ClientCall.Listener<RespT>() {
@Override
public void onHeaders(Metadata headers) {
System.out.println("Header received" +headers);
super.onHeaders(headers);
}
};
super.start(listener, headers);
}
};
}
};
现在我看到的是,一旦我到达 onHeaders Metohd,程序就会无限期地等待。这正常吗。 header 方法完成后,如何恢复读取正常流数据?
编辑-1
所以链接就像-
@Override
public <ReqT, RespT> ClientCall<ReqT, RespT> interceptCall(
final MethodDescriptor<ReqT, RespT> method, CallOptions callOptions, Channel next) {
return new ForwardingClientCall.SimpleForwardingClientCall<ReqT, RespT>(
next.newCall(method, callOptions)) {
@Override
public void start(Listener<RespT> responseListener, Metadata headers) {
responseListener = new SimpleForwardingClientCallListener<RespT>(responseListener) {
@Override
public void onHeaders(Metadata headers) {
System.out.println("Header found"+ headers);
super.onHeaders(headers);
}
};
ClientCall.Listener<RespT> listener = new ClientCall.Listener<RespT>() {
@Override
public void onHeaders(Metadata headers) {
System.out.println("Header received" +headers);
super.onHeaders(headers);
}
};
super.start(listener, headers);
}
};
}
};
您没有链接到 responseListener
。您应该使用 SimpleForwardingClientCallListener
作为侦听器,类似于您为呼叫所做的。
@Override
public void start(Listener<RespT> responseListener, Metadata headers) {
responseListener = new SimpleForwardingClientCallListener<RespT>(responseListener) {
...
我正在使用 Protoc 3.0 并编写了使用 java 读取 GRPC 流数据的回调方法。
@Override
public <ReqT, RespT> ClientCall<ReqT, RespT> interceptCall(
final MethodDescriptor<ReqT, RespT> method, CallOptions callOptions, Channel next) {
return new ForwardingClientCall.SimpleForwardingClientCall<ReqT, RespT>(
next.newCall(method, callOptions)) {
@Override
public void start(Listener<RespT> responseListener, Metadata headers) {
ClientCall.Listener<RespT> listener = new ClientCall.Listener<RespT>() {
@Override
public void onHeaders(Metadata headers) {
System.out.println("Header received" +headers);
super.onHeaders(headers);
}
};
super.start(listener, headers);
}
};
}
};
现在我看到的是,一旦我到达 onHeaders Metohd,程序就会无限期地等待。这正常吗。 header 方法完成后,如何恢复读取正常流数据?
编辑-1 所以链接就像-
@Override
public <ReqT, RespT> ClientCall<ReqT, RespT> interceptCall(
final MethodDescriptor<ReqT, RespT> method, CallOptions callOptions, Channel next) {
return new ForwardingClientCall.SimpleForwardingClientCall<ReqT, RespT>(
next.newCall(method, callOptions)) {
@Override
public void start(Listener<RespT> responseListener, Metadata headers) {
responseListener = new SimpleForwardingClientCallListener<RespT>(responseListener) {
@Override
public void onHeaders(Metadata headers) {
System.out.println("Header found"+ headers);
super.onHeaders(headers);
}
};
ClientCall.Listener<RespT> listener = new ClientCall.Listener<RespT>() {
@Override
public void onHeaders(Metadata headers) {
System.out.println("Header received" +headers);
super.onHeaders(headers);
}
};
super.start(listener, headers);
}
};
}
};
您没有链接到 responseListener
。您应该使用 SimpleForwardingClientCallListener
作为侦听器,类似于您为呼叫所做的。
@Override
public void start(Listener<RespT> responseListener, Metadata headers) {
responseListener = new SimpleForwardingClientCallListener<RespT>(responseListener) {
...