我正在为一个简单的客户机-服务器应用程序使用GRPC。Stream观察者对象的内部方法(即方法:OnNext()
, onError()
and OnCompleted()
),但打印功能的输出(例如:System.out.printf()
) is not shown on the shell.
For example here:
IntCouple couple = IntCouple.newBuilder().setNumber1(8).setNumber2(9).build();
StreamObserver<Result> responseObserver = new StreamObserver<>() {
@Override
public void onNext(Result res) {
System.out.printf(
"[from server] asynchronous SimpleSum: %d+%d=%d\n",
couple.getNumber1(), couple.getNumber2(), res.getResult()
);
}
@Override
public void onError(Throwable t) {}
@Override
public void onCompleted() {}
};
stub.simpleSum(couple, responseObserver);
onNext()
method is executed but "[from server] asynchronous SimpleSum: %d+%d=%d\n"
string is not printed on the shell.
This code is located inside a client-side main method executed through the following Gradle task:
task runClient(type: JavaExec) {
group = 'Run'
classpath sourceSets.main.runtimeClasspath
main = "sumgrpc.SumClient"
}
发布于 2019-06-12 17:37:23
好像语法有问题。指出一个问题-应该使用%n代替\n(行分隔符)。
https://stackoverflow.com/questions/-100007004
复制相似问题