// 其中QueryStrategies.MSPID_SCOPE_SINGLE /** * @typedef DefaultQueryHandlerStrategies * @memberof module:fabric-network * @property {function} MSPID_SCOPE_SINGLE Query any one of the event hubs for the connected organisation. Continue * to use the same event hub for all queries unless it fails. 查询通过所连接组织的任何一个活动节点。每次查询都使用相同的节点,除非发生查询失败。 * @property {function} MSPID_SCOPE_ROUND_ROBIN Query any one of the event hubs for the connected organisation. * Use the next available peer for each successive query. 查询通过所连接组织的任何一个活动节点。在每次成功查询之后使用下一个有效的节点。 */
// 事件策略,默认是等待同一个组织下的所有节点响应事件。 /** * @typedef DefaultEventHandlerStrategies * @memberof module:fabric-network * @property MSPID_SCOPE_ALLFORTX Listen for transaction commit events from all peers in the client identity's * organization. 侦听来自客户端标识组织中所有对等方的事务提交事件。 * The [submitTransaction]{@link module:fabric-network.Contract#submitTransaction} function will wait until successful * events are received from <em>all</em> currently connected peers (minimum 1). 函数将等待,直到从所有当前连接的对等方接收到成功的事件(至少1个)。 * @property MSPID_SCOPE_ANYFORTX Listen for transaction commit events from all peers in the client identity's * organization. * The [submitTransaction]{@link module:fabric-network.Contract#submitTransaction} function will wait until a * successful event is received from <em>any</em> peer. 函数将一直等到从任何对等方接收到成功的事件。 * @property NETWORK_SCOPE_ALLFORTX Listen for transaction commit events from all peers in the network. * 侦听来自网络中所有对等方的事务提交事件。 * The [submitTransaction]{@link module:fabric-network.Contract#submitTransaction} function will wait until successful * events are received from <em>all</em> currently connected peers (minimum 1). 函数将等待,直到从所有当前连接的对等方接收到成功的事件(至少1个)。 * @property NETWORK_SCOPE_ANYFORTX Listen for transaction commit events from all peers in the network. * The [submitTransaction]{@link module:fabric-network.Contract#submitTransaction} function will wait until a * successful event is received from <em>any</em> peer. 函数将一直等到从任何对等方接收到成功的事件。 */
/** * Handles events for a given transaction. Used to wait for a submitted transaction to be successfully commited to * the ledger. * Delegates to an event strategy to decide whether events or errors received should be interpreted as success or * failure of a transaction. * 委托给事件策略,以决定接收到的事件或错误是应解释为事务成功还是事务失败。 * @private */ class TransactionEventHandler {
Begin Transaction Insert Into TransactionRecord (Transaction Id, Transaction Data) Queue Message (Transaction Id, Transaction Data) End Transaction
Result = Execte Blockchain Commit
If Result Failed # 如果发生失败,移除队列信息。 Begin Transaction Remove Queue Transaction Id return Failed Message End Transaction Else Begin Transaction Get Other Data Form Query Result Insert Into Other Data To DB Remove Queue Transaction Id return Success Message End Transaction End
# 区块链网络上查询对应的区块ID。 Execte Blockchain Query Transaction ID
# 存在表示交易执行成功 If Exist Begin Transaction Get Other Data Form Query Result Insert Into Other Data To DB Remove Queue Transaction Id End Transaction # 这里不在执行重试。 Else Begin Transaction Remove Queue Transaction Id End Transaction End If End for