Class: EventHub

EventHub

The EventHub class is used to distribute events from an event source(peer)

new EventHub()

Constructs an unconnected EventHub

Methods


connect()

Establishes connection with peer event source

disconnect()

Disconnects the connection to the peer event source. Will close all event listeners and send an `Error` to all listeners that provided an "onError" callback.

isconnected()

Get connected state of eventhub
Returns:
true if connected to event source, false otherwise

registerBlockEvent(onEvent, onError)

Register a callback function to receive block events. This EventHub instance must be connected to a remote peer's event hub before registering for events by calling the "connect()" method.
Parameters:
Name Type Description
onEvent function Function that takes a single parameter which is a JSON object representation of type GRPC message "Block" from lib/proto/common/common.proto.
onError function optional callback function to be notified when this event hub is shutdown.
See:
Returns:
This is the block registration number that must be used to unregister (see unregisterBlockEvent)
Type
int

registerChaincodeEvent(ccid, eventname, onEvent, onError)

Register a callback function to receive chaincode events. This EventHub instance must be connected to a remote peer's event hub before registering for events by calling the "connect()" method.
Parameters:
Name Type Description
ccid string string chaincode id
eventname string string The regex string used to filter events
onEvent function callback function for filter matches that takes a single parameter which is a json object representation of type "message ChaincodeEvent" from lib/proto/chaincode_event.proto
onError function optional callback function to be notified when this event hub is shutdown.
Returns:
ChainCodeCBE object that should be treated as an opaque handle used to unregister (see unregisterChaincodeEvent)
Type
object

registerTxEvent(txid, onEvent, onError)

Register a callback function to receive transactional events. This EventHub instance must be connected to a remote peer's event hub before registering for events by calling the "connect()" method.
Parameters:
Name Type Description
txid string string transaction id
onEvent function Function that takes a parameter which is a json object representation of type "message Transaction" from lib/proto/fabric.proto and a parameter which is a boolean that indicates if the transaction is invalid (true=invalid)
onError function optional callback function to be notified when this event hub is shutdown.

setPeerAddr(peeraddr, opts)

Set peer url for event source

Note: Only use this if creating your own EventHub. The chain class creates a default eventHub that most Node clients can use (see eventHubConnect, eventHubDisconnect and getEventHub).

Parameters:
Name Type Description
peeraddr string peer url
opts object An Object that may contain options to pass to grpcs calls
- pem {string} The certificate file, in PEM format, to use with the gRPC protocol (that is, with TransportCredentials). Required when using the grpcs protocol.
- ssl-target-name-override {string} Used in test environment only, when the server certificate's hostname (in the 'CN' field) does not match the actual host endpoint that the server process runs at, the application can work around the client TLS verify failure by setting this property to the value of the server certificate's hostname
- any other standard grpc stream options will be passed to the grpc service calls directly

unregisterBlockEvent(The)

Unregister the block event listener with the block registration number.
Parameters:
Name Type Description
The int block registration number that was returned during registration.

unregisterChaincodeEvent(cbe)

Unregister chaincode event registration
Parameters:
Name Type Description
cbe object ChainCodeCBE handle return from call to registerChaincodeEvent.

unregisterTxEvent(txid)

Unregister transactional event registration.
Parameters:
Name Type Description
txid string transaction id