You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Event Manager for both internal and external events e.g Azure Service Bus, RabbitMQ, etc.
Basic Example
Initialize
// For all the initializations, It can happen on app bootup like:/* --------- File: app.js --------- */importEventManagerfrom'nodejs-event-manager';constmyEventManager=EventManager.getInstance();// Add Azure service bus credentialsconstconfig={name: 'samsoft-topic',subscription: ['samsoft-email-sub','samsoft-blockchain-sub'],connectionString: ''};myEventManager.initialize(config);
Consumer
// Note: You must listen before emitting any eventsconstlistenEventMgr=EventManager.getInstance();listenEventMgr.on('samsoft-email-sub',async(payload: EventResponse)=>{console.log({label: payload.getSource(),body: payload.getBody()});awaitpayload.complete();});listenEventMgr.on('samsoft-email-sub:notification:send',async(payload: EventResponse)=>{console.log({label: payload.getSource(),body: payload.getBody()});awaitpayload.complete();});
Producer
/* --------- File user.activity.service.js --------- */constsenderMgr=EventManager.getInstance();// For external event, use azure or rabbitMqsenderMgr.emit(['samsoft-blockchain-sub','samsoft-email-sub'],{body: {name: 'samuel',profession: 'Software engineer'},source: 'azure'});// For internal event handle, use node as source or leave blanksenderMgr.emit('samsoft-blockchain-sub:notification:send',{body: {name: 'samuel',profession: 'Software engineer'}source: 'node'});