如何使用 HLF 中的事件通知客户端块提交 and/or 事务状态?

How to notify client of block commit and/or transaction status using events in HLF?

我正在处理一个需要通知任何给定区块链交易状态的客户端。为此,我正在学习如何利用事件来实现这一目标。我尝试参考 HLF 1.4 事件的官方文档(发现 here) but the link to the SDK documentation is dead. I also found this question 但提供的链接也都失效了。

然后我遇到了 Fabric Gateway 实现(提到 here), and I found BlockListenerTest,它构成了这个问题的基础。


我当前的临时代码如下所示:

BlockEventSourceFactory factory = BlockEventSourceFactory.getInstance();
BlockEventSource blockEventSource = factory.newBlockEventSource(channel);
blockEventSource.addBlockListener(blockEvent -> {
    System.out.println("[zzzzz] Block number is " + blockEvent.getBlockNumber());
});
channel.sendTransaction(responses);
blockEventSource.close();

在我的 Java 链代码中,我调用 stub.setEvent("myEventName", null) 来设置事件。

问题是,我没有看到我的调试输出,而且我不确定我做错了什么,所以如果有人能指导我找到正确的资源以供参考,我将不胜感激, and/or 帮助我使上面的代码以某种方式工作。


(如果还有其他需要我提供的信息,请通过评论告诉我,我会在这里添加。)

要使用高级网关 SDK,您需要首先创建一个网关对象,然后从中获取一个网络对象(使用示例代码 here as a start). From the network object, you can invoke addBlockListener() 传入您的消费者函数。然后当您调用在您的合同对象上提交事务,您的侦听器应该被调用。

在测试方面,您最好查看场景测试代码 here, here and here 以获取使用示例。

I tried referring to the official documentation on events in HLF 1.4 (found here) but the link to the SDK documentation is dead. I also found this question but the provided links are all dead as well.

我签到了 fabric-sdk-node docs. I found there are three tutorials about events who may help you to solve your problem. They are transaction-commit-events.md, eventcheckpointer.md and Listeningtoevents.md

  1. Transaction-commit-events 提供了一个标题为 "Event handling strategies" 的特殊部分。
  2. Eventcheckpointer.md 提供了一种重播对等点发出的错过事件的方法,它还概述了发出的事件。
  3. Listeningtoevents.md 还包含一个讨论事件的部分。它还对三种不同类型的事件进行了解释。

希望这三个文件能帮助您解决问题,掌握HLF。

奖金: Fabric 社区很棒。请务必加入此 Fabric-SDK channel or check other fabric chat channels(请参阅聊天部分)。