1.0.1 • Published 8 years ago
nats-event-ex v1.0.1
Nats Event EX
Extends nats event with enforced protocol.
Features
- Protocol enforced
- Default error handler
Protocol
Usage
Install package:
npm install nats-event-exImport an use:
const eventEx = require('nats-event-ex')('nats://localhost:4222')
.setQueueGroup(SERVICE_NAME)Basic Usage:
eventEx.listen('book.created', async (book) => {await readBook(book)})
eventEx.send('book.created', {name: 'Good Book'})Default error handler:
eventEx.listen('error', async () => {throw new Error('Wops!')})
eventEx.send('error')
// error will be logged by simple-json-errorAPI
This module is based on nats-event, and that module is based on node-nats. Please check their docs for more detailed apis.
module.exports
func(options) => eventEx
optionscould be:- an nats url string for single server, such as
nats://localhost:4222 - an nats url string for cluster servers, such as
nats://192.168.0.1:4222,nats://192.168.0.2:4222 - nats connect options
- an nats url string for single server, such as
eventEx.listen
func(name, handler)
handler: async (data, input, subject)
eventEx.send
async func(name, data, options)
optionsis optional, which may contains:- eventId: optional