Corda RPC:从未订阅过从 RPC 返回的热可观察对象

Corda RPC: A hot observable returned from an RPC was never subscribed to

我基于Java Template构建了一个CorDapp。最重要的是,我创建了一个 React 前端。现在,我想从我的前端开始一个流程。为此,我修改了模板服务器,以便控制器启动我的流程:

@GetMapping(value = "/templateendpoint", produces = "text/plain")
    private String templateendpoint() {
        proxy.startTrackedFlowDynamic(issueTokens.class, 30, "O=Bob, L=Berlin, C=DE");
        return "The flow was started";  
    }

此操作确实启动了向 Bob 发放 30 个令牌的流程。通过查询 Bob 的保险库,我可以看到流程是成功的。但是,我在模板服务器上收到以下错误:

RPCClientProxyHandler.onRemoval - A hot observable returned from an RPC was never subscribed to.
This wastes server-side resources because it was queueing observations for retrieval.
It is being closed now, but please adjust your code to call .notUsed() on the observable to close it explicitly. (Java users: subscribe to it then unsubscribe). 
If you aren't sure where the leak is coming from, set -Dnet.corda.client.rpc.trackRpcCallSites=true on the JVM command line and you will get a stack trace with this warning.

第一次交易后,我无法开始另一个流程。 .notUsed() 方法仅适用于 Kotlin。但是,我找不到一种有效的方法来订阅然后取消订阅 observable。

谁能给我一个例子,说明如何用 Corda 流程实现这个?此外,将信息从前端传递到控制器的最实用方法是什么 class,以便将其用作流参数?

出现错误的原因是客户端的Observable被垃圾回收了。

括号中已经提供了解决方案- (Java 用户:订阅然后退订)

所以在你的情况下,你可以这样做:

Subscription subs = updates.subscribe();
subs.unsubscribe();

可能更实用的方法是将可观察实例保留为私有属性 - 这样它就不会被垃圾回收。即

private Observable observable;

参考:https://docs.corda.net/docs/corda-os/4.4/clientrpc.html#observables