Skip to content

Commit

Permalink
FABN-1210 NodeSDK Chaincode events as array
Browse files Browse the repository at this point in the history
Allow all the chaincode events found in a block to be
sent  at one time rather than sent  one at a time.
This will be controlled by a new setting on the chaincode
listener registration, "as_array", the default will
be to send as before, one at a time.

Change-Id: I1dd244eea8743b0394f0feee77068cc1582763bd
Signed-off-by: Bret Harrison <[email protected]>
  • Loading branch information
harrisob committed May 1, 2019
1 parent 826287d commit 5a361ae
Show file tree
Hide file tree
Showing 8 changed files with 365 additions and 266 deletions.
30 changes: 30 additions & 0 deletions docs/tutorials/channel-events.md
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,11 @@ channel-based event service once the event has been seen. The default is false.
When not set and the endBlock has been set the ChannelEventHub instance
will automatically disconnect itself.

* {boolean} `as_array` -- (Optional) This setting indicates to the
`ChannelEventHub` instance to send all chaincode events to the
callback as array rather than one at a time. This setting is only
available for chaincode events.

### Get a Channel-based Event Hub
Use the fabric-client {@link Channel}
{@link Channel#newChannelEventHub newChannelEventHub} object to
Expand Down Expand Up @@ -664,6 +669,31 @@ return Promise.all([event_monitor, send_trans]);
}).then((results) => {
```

The default is to receive the chaincode events one at a time, however
it would be difficult to know that a chaincode event was missed
and to maintain the order within the block.
Using the new option `as_array` the callback will
receive all chaincode events found in a block as an array.
The following example will register a chaincode listener with a callback that
will handle the chaincodes as an array, notice the fifth parameter is an
options object with the 'as_array' true setting.

```
channel_event_hub.registerChaincodeEvent(
'mychaincode',
'myeventname',
(...events) => {
for (const {chaincode_event, block_num, tx_id, tx_status} of events) {
/* process each event */
}
},
(err) =>{
/* process err */
},
{ as_array: true}
);
```

### When using mutual tls
All peers and orderers objects need to use the same client side credentials
for a mutual TLS connection. The credentials must be assigned to the 'client'
Expand Down
Loading

0 comments on commit 5a361ae

Please sign in to comment.