1. Install NATS client and Hemera
npm install nats nats-hemera
Prerequisites
- Node higher than
>6
- npm
>=3.x
or yarn
- NATS
2. Installing NATS
- Download NATS
- Install the path to the executeable in your user path
- Run it!
gnats
Basic Usage
const Hemera = require('nats-hemera')
const nats = require('nats').connect()
const hemera = new Hemera(nats, {
logLevel: 'info'
})
hemera.ready(() => {
hemera.add(
{
topic: 'math',
cmd: 'add'
},
function(req, cb) {
cb(null, req.a + req.b)
}
)
hemera.act(
{
topic: 'math',
cmd: 'add',
a: 1,
b: 2
},
function(err, resp) {
this.log.info(resp, 'Result')
}
)
})