Event Receiver
As there is a bit of boilerplate code needed to start receiving events,
a simple ReliableReceiver
helper is provided.
Only _onEvents
member needs to be overridden.
API
-
contructor([ccm])
ccm
- passed to internally created Executor instance.- Receiver listens for
close
events of theccm
to properly shutdown.
-
start(endpoint, credentials, options)
endpoint
,credentials
andoptions
are passed toCCM#register()
-
Additional
options
keys:component
- component name, “LIVE” by defaultwant
- event filtering parameter, if any
-
stop()
- Stop receiver processing
-
_registerReceiver(as, executor, options)
- Override to use custom ReliableReceiverService instance
-
_newEvents(as, events)
- Override to use it instead of
newEvents
handler.
- Override to use it instead of
Async event API
receiverError
- upon event processing error.workerError
- upon general worker error.newEvents
- can be used to sniff raw delivery of events.ready
- upon receiver getting ready to process events.
Example
const ReliableReceiver = require( 'futoin-eventreceiver/ReliableReceiver' );
const receiver = new ReliableReceiver( ccm );
receiver.on('newEvents', (events) => {
// process
} );
receiver.start( endpoint, credentials, { want: [ 'EVT_TYPE' ] } );