首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >print在Stream观察者方法中不工作

print在Stream观察者方法中不工作
EN

Stack Overflow用户
提问于 2019-06-12 08:12:47
回答 1查看 0关注 0票数 0

我正在为一个简单的客户机-服务器应用程序使用GRPC。Stream观察者对象的内部方法(即方法:OnNext(), onError() and OnCompleted()),但打印功能的输出(例如:System.out.printf()) is not shown on the shell.

For example here:

代码语言:txt
复制
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:

代码语言:txt
复制
task runClient(type: JavaExec) {
    group = 'Run'
    classpath sourceSets.main.runtimeClasspath
    main = "sumgrpc.SumClient"
}
EN

回答 1

Stack Overflow用户

发布于 2019-06-12 17:37:23

好像语法有问题。指出一个问题-应该使用%n代替\n(行分隔符)。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/-100007004

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档