如何订阅和查看来自 Hyperledger Composer 交易的事件
How to subscribe to and see events from Hyperledger Composer transactions
我是 运行 一个 NodeJS 服务器,使用以下代码连接到 Hyperledger 运行时:
const BusinessNetworkConnection = require("composer-client")
.BusinessNetworkConnection;
this.businessNetworkConnection = new BusinessNetworkConnection();
this.CONNECTION_PROFILE_NAME = "hlfv1";
this.businessNetworkIdentifier = "testNetwork";
this.businessNetworkConnection
.connect(
this.CONNECTION_PROFILE_NAME,
this.businessNetworkIdentifier,
"admin",
"adminpwd"
)
.then(result => {
this.businessNetworkDefinition = result;
console.log("BusinessNetworkConnection: ", result);
})
.then(() => {
// Subscribe to events.
this.businessNetworkConnection.on("events", events => {
console.log("**********business event received**********", events);
});
})
// and catch any exceptions that are triggered
.catch(function(error) {
throw error;
});
我在 result
对象中看到建立连接后返回的数据,这是已部署的正确网络数据。
但是,当我提交交易并通过我生成的 REST API 发出请求时,我的服务器看不到任何事件。在 Historian 中,我可以看到事件已发出。我还应该做些什么来查看我的交易发出的那些事件吗?
我试过同样的测试,我可以收到事件。我比较了我的测试代码和你的,我发现了以下差异:
this.bizNetworkConnection.on('events'
this.bizNetworkConnection.on('event'
希望对您有所帮助。
我是 运行 一个 NodeJS 服务器,使用以下代码连接到 Hyperledger 运行时:
const BusinessNetworkConnection = require("composer-client")
.BusinessNetworkConnection;
this.businessNetworkConnection = new BusinessNetworkConnection();
this.CONNECTION_PROFILE_NAME = "hlfv1";
this.businessNetworkIdentifier = "testNetwork";
this.businessNetworkConnection
.connect(
this.CONNECTION_PROFILE_NAME,
this.businessNetworkIdentifier,
"admin",
"adminpwd"
)
.then(result => {
this.businessNetworkDefinition = result;
console.log("BusinessNetworkConnection: ", result);
})
.then(() => {
// Subscribe to events.
this.businessNetworkConnection.on("events", events => {
console.log("**********business event received**********", events);
});
})
// and catch any exceptions that are triggered
.catch(function(error) {
throw error;
});
我在 result
对象中看到建立连接后返回的数据,这是已部署的正确网络数据。
但是,当我提交交易并通过我生成的 REST API 发出请求时,我的服务器看不到任何事件。在 Historian 中,我可以看到事件已发出。我还应该做些什么来查看我的交易发出的那些事件吗?
我试过同样的测试,我可以收到事件。我比较了我的测试代码和你的,我发现了以下差异:
this.bizNetworkConnection.on('events'
this.bizNetworkConnection.on('event'
希望对您有所帮助。