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 <beharrison@nc.rr.com>
  • Loading branch information
harrisob committed May 23, 2019
1 parent 992099f commit 813338e
Show file tree
Hide file tree
Showing 8 changed files with 380 additions and 265 deletions.
25 changes: 25 additions & 0 deletions docs/tutorials/channel-events.md
Original file line number Diff line number Diff line change
Expand Up @@ -694,6 +694,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
234 changes: 138 additions & 96 deletions fabric-client/lib/ChannelEventHub.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion fabric-client/test/Channel.js
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ describe('Channel', () => {

it('returns the same channel event hub on subsequent calls', () => {
channel.addPeer(peer1);
const channelEventHub = channel.newChannelEventHub(peer1.getName());
const channelEventHub = channel.getChannelEventHub(peer1.getName());
expect(channel.getChannelEventHub(peer1.getName())).to.deep.equal(channelEventHub);
});

Expand Down
Loading

0 comments on commit 813338e

Please sign in to comment.