Fastify plugin to integrate Hemera
npm install --save fastify-hemera
fastify.register(require('fastify-hemera'), {
plugins: [require('hemera-mongo-store')],
hemera: {
name: 'test',
logLevel: 'debug'
},
nats: 'nats://localhost:4242'
})
Full list of hemera plugins
$ docker-compose up
$ node example.js
$ curl http://localhost:3000/reply?a=33&b=22
Simple
fastify.route({
method: 'GET',
url: '/math/add',
handler: (req, reply) => {
reply.act({ topic: 'math', cmd: 'add', a: req.query.a, b: req.query.b })
}
})
Async / Await
fastify.route({
method: 'GET',
url: '/math/add',
handler: async function (req, reply) {
let resp = await req.hemera.act({ topic: 'math', cmd: 'add', a: req.query.a, b: req.query.b })
// access result
resp.data
// retain parent context
resp = resp.context.act(...)
}
})
Testsuite makes use of hemera-testsuite, so your setup should meet it's prerequisits, esp.:
A nats server must be installed on your machine nats.io and executable as gnatsd
. So add nats-server
as gnatsd
to your PATH
as alias, link whatever works. Check if it's available:
$ gnatsd --help
Usage: nats-server [options]
[...]
Now test should succeed by running:
$ yarn test