需要设置什么才能让 Hyperledger Composer 事件正常工作?
What needs to be set up for Hyperledger Composer events to work?
我做了以下事情:
- https://hyperledger.github.io/composer/business-network/publishing-events.html
- https://hyperledger.github.io/composer/applications/subscribing-to-events.html
文档使您似乎只需要在 Node.js 服务器中坚持:
businessNetworkConnection.on('event', (event) => {
// event: { "$class": "org.namespace.BasicEvent", "eventId": "0000-0000-0000-000000#0" }
console.log(event);
});
但我的情况没有任何反应。我可以通过 playground UI 看到我的事务发出事件,但它们没有访问我的 Node.js 服务器。
我是否必须设置自己的 websocket 服务器之类的?
所以
在您的 TP 代码中发出您的事件(您已经完成了)-示例 -> https://github.com/hyperledger/composer-sample-networks/blob/master/packages/trade-network/lib/logic.js#L28 or as shown at https://hyperledger.github.io/composer/business-network/publishing-events.html
在您的模型文件中定义了事件 class - 例如 -> https://github.com/hyperledger/composer-sample-networks/blob/master/packages/trade-network/models/trading.cto#L25 - 然后更新到您之前使用 composer network update
部署的运行时业务网络
event
中的 eventId 属性 始终与发出事件的事务的 transactionId 相同。
我做了以下事情:
- https://hyperledger.github.io/composer/business-network/publishing-events.html
- https://hyperledger.github.io/composer/applications/subscribing-to-events.html
文档使您似乎只需要在 Node.js 服务器中坚持:
businessNetworkConnection.on('event', (event) => {
// event: { "$class": "org.namespace.BasicEvent", "eventId": "0000-0000-0000-000000#0" }
console.log(event);
});
但我的情况没有任何反应。我可以通过 playground UI 看到我的事务发出事件,但它们没有访问我的 Node.js 服务器。
我是否必须设置自己的 websocket 服务器之类的?
所以
在您的 TP 代码中发出您的事件(您已经完成了)-示例 -> https://github.com/hyperledger/composer-sample-networks/blob/master/packages/trade-network/lib/logic.js#L28 or as shown at https://hyperledger.github.io/composer/business-network/publishing-events.html
在您的模型文件中定义了事件 class - 例如 -> https://github.com/hyperledger/composer-sample-networks/blob/master/packages/trade-network/models/trading.cto#L25 - 然后更新到您之前使用
composer network update
部署的运行时业务网络event
中的 eventId 属性 始终与发出事件的事务的 transactionId 相同。