simple-eventhubs-framework
v0.1.6
Published
A simple framework for node services to use eventhubs
Downloads
4
Readme
Provided is an Event Beacon as
import { EventBeacon } from 'simple-eventhubs-framework';
const beacon = new EventBeacon();
const myListener = async event => {
const {
action,
transaction_id,
payload
} = event;
};
EventBeacon.register
register callbacks
props the keyword argument object
props.hub string the eventhub to unregister the listener
props.callback Function the specific callback to unregister (optional), default: Any/All
props.action string the action to unregister callbacks for, default Any/All
props.transaction_id string the transactionId to unregister callbacks for, default Any/All.
props.consumerGroup string the consumergroup of the subscription, default "$Default"
props.once boolean when an acceptable event has been received, shut this down/unregister this listener.
Returns Promise resolved by boolean true on success
const myCallbackFn = event => { ....custom event handler code..... }
await myBeaconInstance.register({
hub: "myHub",
action: "my-action",
consumerGroup: "myConsumer",
transaction_id: "some_specific_transaction_were_interested_in",
once: true, // unregister once this event has been received and callback fired.
callback: myCallbackFn
})
EventBeacon.unregister
Unregister callbacks
props the keyword argument object
props.hub string the eventhub to unregister the listener
props.callback Function the specific callback to unregister (optional), default: Any/All
props.action string the action to unregister callbacks for, default Any/All
props.transaction_id string the transactionId to unregister callbacks for, default Any/All.
props.consumerGroup string the consumergroup of the subscription, default "$Default"
Returns Promise resolved by boolean true on success
const myCallbackFn = event => { ....custom event handler code..... }
await myBeaconInstance.unregister({
hub: "myhub",
action: "my-action",
transaction_id: "saf87-asdf897asf-asdf89asdf-sadf",
consumerGroup: "$Default",
callback: myCallbackFn
});
EventBeacon.dispatch
Dispatch an event
props the keyword argument object
props.hub string the eventhub to unregister the listener
props.action string the action to unregister callbacks for, default Any/All
props.transaction_id string optional tracking id for this event
props.payload object key/prop object for this event - must be JSON friendly (ie not cyclic, all key vals are primitives and not functions etc)
Returns Promise resolved by boolean true on success
const result = await MyBeaconInstance.dispatch({
hub: "myhub",
action: "my-action"
payload: {
this: "that"
}
})