Git Product home page Git Product logo

hemera's Introduction

Hemera

License MIT Build Status Build Status Coverage Status Gitter JavaScript Style Guide Known Vulnerabilities lerna

A Node.js microservices toolkit for the NATS messaging system
Run on repl.it


Note: Are you looking for the next generation API Developer Platform? 🔎 Have a look at: WunderGraph Turn your services, databases and 3rd party APIs into a secure unified API in just a few minutes. 🪄


📓 Getting Started

Hemera (/ˈhɛmərə/; Ancient Greek: Ἡμέρα [hɛːméra] "day") is a small wrapper around the official NATS driver. NATS is a simple, fast and reliable solution for the internal communication of a distributed system. It chooses simplicity and reliability over guaranteed delivery. We want to provide a toolkit to develop micro services in an easy and powerful way. We provide a pattern matching RPC style. You don't have to worry about the transport. NATS is powerful.

With Hemera you have the best of both worlds. Efficient pattern matching to have the most flexibility in defining your RPC's. It doesn't matter where your server or client lives. You can start as many services you want on different hosts to ensure maximal availability. The only dependency you have is a single binary of ~10MB. Mind your own business NATS will do the rest for you:

The key features of NATS in combination with Hemera are:

  • Lightweight: The Hemera core is small as possible and provide an extensive plugin system.
  • Location transparency: A service may be instantiated in different locations at different times. An application interacting with an service and does not know the service physical location.
  • Service Discovery: You don't need a service discovery all subscriptions are managed by NATS.
  • Load Balancing: Requests are load balanced (random) by NATS mechanism of "queue groups".
  • Packages: We provide reliable and modern plugins to the community.
  • High performant: NATS is able to handle million of requests per second.
  • Scalability: Filtering on the subject name enables services to divide work (perhaps with locality).
  • Fault tolerance: Auto-heals when new services are added. Configure cluster mode to be more reliable.
  • Auto-pruning: NATS automatically handles a slow consumer and cut it off.
  • Pattern driven: Define RPC's in JSON and use the flexibility of pattern-matching.
  • Request & Reply: By default point-to-point involves the fastest or first to respond.
  • Publish & Subscribe: Hemera supports all features of NATS. This includes wildcards in subjects and normal publish and fanout mechanism.
  • Tracing: Builtin tracing capabilities but we also provide plugin for Jaeger.
  • Monitoring: NATS server can be monitored by cli or a dashboard.
  • Payload validation: Create your own validator or use existing plugins e.g hemera-joi or hemera-ajv.
  • Serialization: Use custom serializer e.g hemera-mgspack.
  • Metadata: Transfer metadata across services or attach contextual data to tracing systems.
  • Dependencies: NATS is a single binary of ~10MB and can be deployed in seconds.
  • Typescript: We provide typings.

Built in protection

  • Process policy: Will exit the process when the policy (memory, event loop) could not be fullfilled (Option: heavy).
  • Message loop detection: Will return an error if you call a route recursively (Option: maxRecursion).
  • Safe default JSON serializer: Provides a deterministic version and will also gracefully handle circular structures.

Who's using Hemera?

appcom-interactive amerbank savicontrols mercado unico
appcom interactive amerbank savicontrols mercado unico

Get Involved

  • Contributing: Pull requests are welcome!
    • Read CONTRIBUTING.md and check out our help-wanted issues
    • Submit github issues for any feature enhancements, bugs or documentation problems
  • Support: Join our gitter chat to ask questions to get support from the maintainers and other Hemera developers
  • Discuss: Tweet using the #HemeraJs hashtag

Contributing

Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.

Supported Node Versions

Support policy for Nodejs versions follows Nodejs release support. We will support and build hemera on even Nodejs versions that are current or in maintenance.

Professional services

Hemera is free for any use (MIT license). If you are in production don't miss the professional support service. For courses and training send me an email to [email protected] or contact me private on Gitter

Sponsorship

Development of the hemera core module generously supported by contributions from individuals and corporations. If you are benefiting from hemera and would like to help keep the project financially sustainable, please visit Dustin Deus Patreon page, his Paypal Me or contact him via email.

hemera's People

Contributors

aruss avatar digital-stoic avatar dzenly avatar geekup-khanhtq avatar greenkeeper[bot] avatar haroenv avatar keks0r avatar nalexandrov avatar osoianmarcel avatar rbpinheiro avatar starptech avatar tchandler avatar veeramarni avatar zarathustra323 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

hemera's Issues

Add middlewares [Investigation]

Hii, is there any way to use cache for certains hemera services.

I'm looking for something that I've used in Express, a middleware function that caches end points.

Thanks!

Error on install

During installation, this error occurs:
'flow-remove-types' is not recognized as an internal or external command, operable program or batch file.

I'm using:

  • Windows 7
  • Node 6.9.0

why hemera auto start many node instance?

why i'm run with:

NODE_ENV=devserver NODE_CONFIG_DIR=./config node /mnt/data/webapps/ra-micro-service/index.js &

and start many node instance like below, and when kill -9 , they are auto restart. why?

root      59761 53.0  0.1 943248 36660 ?        Rl   11:14   0:00 node /mnt/data/webapps/ra-micro-service/index.js                                                                     
root      59767 50.0  0.0 941412 31264 ?        Rl   11:14   0:00 node /mnt/data/webapps/ra-micro-service/index.js                                                                     
root      59772 45.0  0.1 943716 35548 ?        Rl   11:14   0:00 node /mnt/data/webapps/ra-micro-service/index.js                                                                     
root      59795 36.0  0.0 934816 30392 ?        Rl   11:14   0:00 node /mnt/data/webapps/ra-micro-service/index.js                                                                     
root      59801 32.0  0.0 935640 29084 ?        Rl   11:14   0:00 node /mnt/data/webapps/ra-micro-service/index.js                                                                     
root      59807 34.0  0.0 934628 29516 ?        Rl   11:14   0:00 node /mnt/data/webapps/ra-micro-service/index.js                                                                     
root      59814 33.0  0.0 935640 29472 ?        Rl   11:14   0:00 node /mnt/data/webapps/ra-micro-service/index.js                                                                     
root      59825 32.0  0.0 940240 32164 ?        Rl   11:14   0:00 node /mnt/data/webapps/ra-micro-service/index.js                                                                     
root      59832 28.0  0.0 930768 24688 ?        Rl   11:14   0:00 node /mnt/data/webapps/ra-micro-service/index.js                                                                     
root      59842 25.0  0.0 930720 24892 ?        Rl   11:14   0:00 node /mnt/data/webapps/ra-micro-service/index.js                                                                     
root      59852 22.0  0.0 889792 21140 ?        Rl   11:14   0:00 node /mnt/data/webapps/ra-micro-service/index.js                                                                     
root      59858 19.0  0.0 889280 20268 ?        Rl   11:14   0:00 node /mnt/data/webapps/ra-micro-service/index.js

hemera-web have some errors.

when i'm run: node web.js in examples.

[2017-05-12T06:43:49.141Z] ERROR (hemera-f09583d25d6f5b4d/21188 on yaochen): No topic to request
HemeraError
at Hemera.act (G:\source\node\微服务\hemera\packages\hemera\lib\index.js:893:19)
at _server.Micro (G:\source\node\微服务\hemera\packages\hemera-web\lib\index.js:71:27)
at resolve (G:\source\node\微服务\hemera\packages\hemera-web\node_modules\micro\lib\server.js:24:34)
at Promise._execute (G:\source\node\微服务\hemera\packages\hemera-web\node_modules\bluebird\js\release\debuggability.js:300:9)
at Promise._resolveFromExecutor (G:\source\node\微服务\hemera\packages\hemera-web\node_modules\bluebird\js\release\promise.js:483:18)
at new Promise (G:\source\node\微服务\hemera\packages\hemera-web\node_modules\bluebird\js\release\promise.js:79:10)
at Function.exports.run (G:\source\node\微服务\hemera\packages\hemera-web\node_modules\micro\lib\server.js:24:3)
at Server.server (G:\source\node\微服务\hemera\packages\hemera-web\node_modules\micro\lib\server.js:13:50)
at emitTwo (events.js:106:13)
at Server.emit (events.js:194:7)
at parserOnIncoming (_http_server.js:563:12)
at HTTPParser.parserOnHeadersComplete (_http_common.js:99:23)
HemeraError
at Hemera.act (G:\source\node\微服务\hemera\packages\hemera\lib\index.js:893:19)
at _server.Micro (G:\source\node\微服务\hemera\packages\hemera-web\lib\index.js:71:27)
at resolve (G:\source\node\微服务\hemera\packages\hemera-web\node_modules\micro\lib\server.js:24:34)
at Promise._execute (G:\source\node\微服务\hemera\packages\hemera-web\node_modules\bluebird\js\release\debuggability.js:300:9)
at Promise._resolveFromExecutor (G:\source\node\微服务\hemera\packages\hemera-web\node_modules\bluebird\js\release\promise.js:483:18)
at new Promise (G:\source\node\微服务\hemera\packages\hemera-web\node_modules\bluebird\js\release\promise.js:79:10)
at Function.exports.run (G:\source\node\微服务\hemera\packages\hemera-web\node_modules\micro\lib\server.js:24:3)
at Server.server (G:\source\node\微服务\hemera\packages\hemera-web\node_modules\micro\lib\server.js:13:50)
at emitTwo (events.js:106:13)
at Server.emit (events.js:194:7)
at parserOnIncoming (_http_server.js:563:12)
at HTTPParser.parserOnHeadersComplete (_http_common.js:99:23)

but the browser can response ok.

AddStub.run ignores Validaiton

Hi,

I am currently playing around with hemera and was rewriting a small app from seneca. I am using Joi Validation and wanted to test it with the approach that is documented for unit tests.
This is the Plugin I am trying to test:

function EventStorePlugin (options, next) {
  this.use(require('hemera-joi'))
  this.setOption('payloadValidator', 'hemera-joi')

  this.add(
    {
      topic: 'events',
      cmd: 'add',
      events: Joi.array().required()
    },
    (msg, reply) => {
      msg.events.forEach(store.add)
      reply(null, {success:true})
    }
  )
next()
}

But it seems that Running unit tests against this, is not checking for Validation:
Test

const Hemera = require('nats-hemera')
const Nats = require('hemera-testsuite/natsStub')
const AddStub = require('hemera-testsuite/addStub')
const nats = new Nats()
const h = new Hemera(nats, { logLevel: 'fatal' })
h.use(require('../handlers'))

test('Requires a valid Event', done => {
  expect.assertions(5)
  h.ready(() => {
    AddStub.run(
      h,
      {
        topic: 'events',
        cmd: 'add'
      },
      { events: 1 },
      (err, res) => {
        expect(err).toBeTruthy()
        done()
      }
    )
  })
})

Is there a way of getting validation to work with the AddStub?

node version issue with henera-store (npm error)

Description

Using nodejs 7.6.0, I got an NPM error when installing

Steps to Reproduce

  1. npm install -g n
  2. n 7.6.0
  3. npm install hemera-store

Expected Result

Being able to install hemera-store

Actual Result

NPM error:

0 info it worked if it ends with ok
1 verbose cli [ '/usr/local/bin/node',
1 verbose cli   '/usr/local/bin/npm',
1 verbose cli   'install',
1 verbose cli   'hemera-store' ]
2 info using [email protected]
3 info using [email protected]
4 verbose stack Error: Cannot find module 'internal/fs'
4 verbose stack     at Function.Module._resolveFilename (module.js:470:15)
4 verbose stack     at Function.Module._load (module.js:418:25)
4 verbose stack     at Module.require (module.js:498:17)
4 verbose stack     at require (internal/module.js:20:19)
4 verbose stack     at evalmachine.<anonymous>:18:20
4 verbose stack     at Object.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/cmd-shim/node_modules/graceful-fs/fs.js:11:1)
4 verbose stack     at Module._compile (module.js:571:32)
4 verbose stack     at Object.Module._extensions..js (module.js:580:10)
4 verbose stack     at Module.load (module.js:488:32)
4 verbose stack     at tryModuleLoad (module.js:447:12)
5 verbose cwd /Users/romuald/Documents/devserver/workspace/hemera-playground/microservices-example
6 error Darwin 14.5.0
7 error argv "/usr/local/bin/node" "/usr/local/bin/npm" "install" "hemera-store"
8 error node v7.6.0
9 error npm  v4.1.2
10 error code MODULE_NOT_FOUND
11 error Cannot find module 'internal/fs'
12 error If you need help, you may report this error at:
12 error     <https://github.com/npm/npm/issues>
13 verbose exit [ 1, true ]

Context

  • nats-hemera (core)
  • hemera-zipkin
  • hemera-store
  • hemera-stats
  • hemera-rabbitmq
  • hemera-nsq
  • hemera-arango-store
  • hemera-sql-store
  • hemera-elasticsearch
  • hemera-couchbase-store
  • hemera-mongo-store
  • hemera-joi
  • hemera-parambulator
  • hemera-msgpack
  • hemera-avro
  • hemera-redis-cache
  • hemera-jwt-auth

Your Environment

  • NATS: 0.9.6
  • Hemera: 1.3.2
  • NodeJs: 7.6.0
  • Environment name and version:
  • Operating System and version: OSX 10.10.5

After Failing Tests, PatternNotFound Errors for previously working tests

Description

I have written some functional tests that are passing (TestSet 1) . I now started to create more tests (in another file) that currently fail (TestSet 2). While having this intermediate situation I observed a rather confusing behaviour:
I run my TestSet 1 which passes fine. Now I run all tests, which fails due to TestSet2. Also Jest does not exit, which usually indicates that there are some connections / processes / async things still happening. I kill jest via sigterm. If I now run TestSet 1 alone again, which previously worked I am getting a PatternNotFound Exception.

Also just restarting the NATS server does not solve the issue.

Expected Result

That TestSet 1 always passes, independent of previously ran TestSet 2.

Your Environment

  • NATS: 0.9.6
  • Hemera: 1.3.7
  • NodeJs: 8.1.3
  • Operating System and version: osx

Add nats streaming middleware

Before you submit an issue we recommend you drop into the Gitter community and ask any questions you have or mention any problems you've had getting started with hemera.

Description

Steps to Reproduce

Expected Result

Actual Result

Context

  • nats-hemera (core)
  • hemera-zipkin
  • hemera-store
  • hemera-stats
  • hemera-rabbitmq
  • hemera-nsq
  • hemera-arango-store
  • hemera-sql-store
  • hemera-elasticsearch
  • hemera-couchbase-store
  • hemera-mongo-store
  • hemera-joi
  • hemera-parambulator
  • hemera-msgpack
  • hemera-avro
  • hemera-redis-cache
  • hemera-jwt-auth

Your Environment

  • NATS: X.X.X
  • Hemera: X.X.X
  • NodeJs: X.X.X
  • Environment name and version:
  • Operating System and version:

hemera-web node version requirement

Description

I need a really high version of node to be able to use hemera-web.
hemera-web starts to wok with node 7.6.0
Before that I get an error.

Steps to Reproduce

  1. npm install -g n
  2. n 7.5.0
  3. execute hemera-web example:
const nats = require('nats').connect()
const hemeraWeb = require('hemera-web')
 
const hemera = new Hemera(nats)
hemera.use(hemeraWeb, {
  port: 3000,
  host: '127.0.0.1',
  pattern: {} // default pattern 
})
 
hemera.ready(() => {
  hemera.add({
    topic: 'math',
    cmd: 'add'
  }, (req, cb) => {
    cb(null, req.a + req.b)
  })
})

Expected Result

Having the nodejs script executing

Actual Result

Get an error with the async keyword (I think):

╰─$ node -v
v6.5.0
╭─romuald@C02M2HBKFD57 ~/Documents/devserver/workspace/hemera-playground/microservices-example ‹2.2.5›
╰─$ node products/index.js
/Users/romuald/Documents/devserver/workspace/hemera-playground/microservices-example/node_modules/hemera-web/lib/index.js:35
    this._server = Micro(async (req, res) => {
                               ^
SyntaxError: Unexpected token (
    at Object.exports.runInThisContext (vm.js:76:16)
    at Module._compile (module.js:528:28)
    at Object.Module._extensions..js (module.js:565:10)
    at Module.load (module.js:473:32)
    at tryModuleLoad (module.js:432:12)
    at Function.Module._load (module.js:424:3)
    at Module.require (module.js:483:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (/Users/romuald/Documents/devserver/workspace/hemera-playground/microservices-example/node_modules/hemera-web/index.js:3:13)
    at Module._compile (module.js:556:32)

Context

  • nats-hemera (core)
  • hemera-web

Your Environment

  • NATS: 0.9.6
  • Hemera: 1.3.2
  • NodeJs: 7.5.0
  • Environment name and version:
  • Operating System and version: OSX 10.10.5

Proper way to test services

I'm missing the proper way to test the services (the aither repo doesn't have any besides the load test), and couldn't find a definitive answer. In express, I used superagent, which made the REST testing somewhat easy, and doesn't need to listen on a port

Typescript typings

Does hemera plans to have typescript typings? It's great for new comers to this lib and to ensure proper code structure with self documenting typings

Sometimes it works sometimes it doesn't

I am using mongodb atlas db to store data. When I use find query sometimes it pulls data sometimes it doesn't with the same query...

Here is code snippet:

public showUserByMail(msg: any, done: any): void {
        let __this: any = this;
        let hemera: T = __this;
        
        hemera.act({
            topic: 'mongo-store',
            cmd: 'find',
            collection: 'users',
            query: { email: msg.email }
        }, (err: Error, resp: any) => {
            if (err) {
                done(err);
            }
            console.log(resp)
            if(resp.result.length === 0) {
                done(null, false);
            } else {
                done(null, resp.result[0]);
            }
        })
    }

Cannot read property 'request' of undefined

why i'm use 1.5.6
have some errors

2017-08-25T12:07:06+0800 <debug> app.js:133 (Aedes.self.aedes.authenticate) TypeError: Cannot read property 'request' of undefined
    at NatsTransport.sendRequest (G:\repository\ra\ra-broker\node_modules\nats-hemera\lib\transport.js:113:19)
    at onPreRequestHandler (G:\repository\ra\ra-broker\node_modules\nats-hemera\lib\onPreRequest.js:68:31)
    at ctx._extensions.onClientPreRequest.dispatch (G:\repository\ra\ra-broker\node_modules\nats-hemera\lib\index.js:1019:63)
    at done (G:\repository\ra\ra-broker\node_modules\nats-hemera\lib\util.js:155:15)
    at onClientPreRequestCircuitBreaker (G:\repository\ra\ra-broker\node_modules\nats-hemera\lib\extensions.js:116:5)
    at each (G:\repository\ra\ra-broker\node_modules\nats-hemera\lib\extension.js:28:7)
    at iterate (G:\repository\ra\ra-broker\node_modules\nats-hemera\lib\util.js:160:9)
    at done (G:\repository\ra\ra-broker\node_modules\nats-hemera\lib\util.js:153:15)
    at onClientPreRequest (G:\repository\ra\ra-broker\node_modules\nats-hemera\lib\extensions.js:90:3)
    at each (G:\repository\ra\ra-broker\node_modules\nats-hemera\lib\extension.js:28:7)
    at iterate (G:\repository\ra\ra-broker\node_modules\nats-hemera\lib\util.js:160:9)
    at Function.serialWithCancellation (G:\repository\ra\ra-broker\node_modules\nats-hemera\lib\util.js:163:7)
    at Extension.run (G:\repository\ra\ra-broker\node_modules\nats-hemera\lib\baseExtension.js:57:10)
    at Extension.dispatch (G:\repository\ra\ra-broker\node_modules\nats-hemera\lib\extension.js:31:10)
    at Hemera.act (G:\repository\ra\ra-broker\node_modules\nats-hemera\lib\index.js:1019:40)
    at Aedes.self.aedes.authenticate (G:\repository\ra\ra-broker\app\app.js:110:46)

add custom support for logging

For example, we use winston everywhere, I miss the possibility to link an external logging interface which will be awesome to have. Pino actually breaks our logging stack

Not returning error to api

On api side where is hemera hapi I have basic act request:

createUser(req: HapiRequest, reply: Hapi.ReplyNoContinue) {
        let user: UserCreateInterface = req.payload;

        return req.hemera.act({ topic: 'user-save', type: 'amerbank', payload: user },
            function (err: any, result: any) {

                reply(err || result)
            })
    }

here is add in service:

this.hemera.add({
      topic: 'user-save',
      type: 'amerbank',
      email: Joi.number().required()
    }

In logs I get error messaga:

[api - 7554]: 170908/201422.097, [error] message: child "email" fails because ["email" is required], stack: PreValidationError: child "email" fails because ["email" is required]
[api - 7554]: at Joi.validate (/home/master/Documents/trifecta/user-service/node_modules/hemera-joi/index.js:38:18)

But api returns:
Internal server error

Who is using Hemera in production?

Please answer in this format.

Company Project size What would you like to change? Permission to list your company ?
name small, big everything works like a charm yes, here is my link to the logo

Problems with PUBSUB - PatternNotFound

Description

Problem with PUBSUB:
No handler found for this pattern (PatternNotFound)

Steps to Reproduce

server.js

const Hemera = require('nats-hemera');
const nats = require('nats').connect();
const hemera = new Hemera(nats, {logLevel: 'error'});

hemera.ready(() => {

	// Add service command
	hemera.add({topic: 'service', cmd: 'do'}, (req, cb) => {
		cb(null, {result: 'ok! done! - ' + req.data});

		// Emit an event (one-to-many)
		hemera.act({
			pubsub$: true,
			topic: 'service',
			cmd: 'event',
			payload: 'add was executed!'
		});
	});

	// Subscribe to "topic:payment,cmd:event"
	hemera.add({pubsub$: true, topic: 'service', cmd: 'event'}, req => {
		console.log('event', req);
	});

});

subscriber.js

const Hemera = require('nats-hemera');
const nats = require('nats').connect();
const hemera = new Hemera(nats, {logLevel: 'error'});

hemera.ready(() => {

	// TODO: Check the problem here
	// Subscribe to "topic:payment,cmd:event"
	hemera.add({pubsub$: true, topic: 'service', cmd: 'event'}, req => {
		console.log('event', req);
	});

});

client.js

const Hemera = require('nats-hemera');
const nats = require('nats').connect();
const hemera = new Hemera(nats, {logLevel: 'error'});

hemera.ready(() => {

	// Call service command "topic:service,cmd:do"
	hemera.act({topic: 'service', cmd: 'do', data: 123}, (err, resp) => {
		console.log(err, resp);
	});

});

Steps to Reproduce

1. Start server.js (no output)

node server.js

2. Start subscriber.js (no output)

node subscriber.js

3. Start client.js

node client.js

Output (expected output):

null { result: 'ok! done! - 123' }

4. Now check subscriber.js output (PROBLEM)

Expected Result

Expected subscriber.js output:

event { topic: 'service', cmd: 'event', payload: 'add was executed!' }

Actual Result

Actual subscriber.js result (ERROR):

[2017-07-12T11:49:17.033Z] ERROR (hemera-ff254d962b06-fd3d138ee7f34f5181357a5ba2bfc9e1/765 on ff254d962b06): No handler found for this pattern
    PatternNotFound
        at Hemera._onServerPreRequestHandler (/code/node_modules/nats-hemera/lib/index.js:835:29)
        at ctx._extensions.onServerPreRequest.dispatch (/code/node_modules/nats-hemera/lib/index.js:876:74)
        at done (/code/node_modules/nats-hemera/lib/util.js:155:15)
        at Hemera.onServerPreRequestLoadTest (/code/node_modules/nats-hemera/lib/extensions.js:214:3)
        at each (/code/node_modules/nats-hemera/lib/extension.js:65:14)
        at iterate (/code/node_modules/nats-hemera/lib/util.js:160:9)
        at done (/code/node_modules/nats-hemera/lib/util.js:153:15)
        at Hemera.onServerPreRequest (/code/node_modules/nats-hemera/lib/extensions.js:192:3)
        at each (/code/node_modules/nats-hemera/lib/extension.js:65:14)
        at iterate (/code/node_modules/nats-hemera/lib/util.js:160:9)
[2017-07-12T11:49:17.039Z] ERROR (hemera-ff254d962b06-fd3d138ee7f34f5181357a5ba2bfc9e1/765 on ff254d962b06): No handler found for this pattern
    PatternNotFound
        at Hemera._onServerPreRequestHandler (/code/node_modules/nats-hemera/lib/index.js:835:29)
        at ctx._extensions.onServerPreRequest.dispatch (/code/node_modules/nats-hemera/lib/index.js:876:74)
        at done (/code/node_modules/nats-hemera/lib/util.js:155:15)
        at Hemera.onServerPreRequestLoadTest (/code/node_modules/nats-hemera/lib/extensions.js:214:3)
        at each (/code/node_modules/nats-hemera/lib/extension.js:65:14)
        at iterate (/code/node_modules/nats-hemera/lib/util.js:160:9)
        at done (/code/node_modules/nats-hemera/lib/util.js:153:15)
        at Hemera.onServerPreRequest (/code/node_modules/nats-hemera/lib/extensions.js:192:3)
        at each (/code/node_modules/nats-hemera/lib/extension.js:65:14)
        at iterate (/code/node_modules/nats-hemera/lib/util.js:160:9)
event { topic: 'service', cmd: 'event', payload: 'add was executed!' }

**Very important: ** Subscriber recevied the event, but with errors.

Context

  • nats-hemera (core)

Your Environment

  • NATS: 0.9.6 (server version)
  • Hemera: 1.3.12
  • NodeJs: v8.1.2
  • Environment name and version: no env. name
  • Operating System and version: Docker (MacOS), Images: node:alpine, nats:latest

Add specific middleware only for server method.

It would be nice to have the chance to define middleware only for specific add

I prefer a chaining syntax instead parameter overloading.

hemera.add({
  topic: 'test',
  cmd: 'add'
}).use(function(req, resp, next) {
//process request
})
.end(function(req, cb) {
   cb()
})

Approach:
Providing an interface to attach handlers to the actMeta object. When the add is called we could return an interface.

    return new Add(actMeta)
    /*
     Interface:
       use(<function)
       end(<function>)
     */

Those handlers can be executed in serial when a message arrived https://github.com/hemerajs/hemera/blob/master/packages/hemera/lib/index.js#L510.

Proposal: Hemera.add should throw BusinessError if promise-based handler rejects

Description

It would be nice if returning a promise from a Hemera.add handler worked the same as using a callback. For example, I would expect both services below to behave identically.

hemera.ready(() => {
  let Joi = hemera.joi

  const myPromise = (fail) => (
    new Promise((resolve, reject) => {
      if (fail) {
        return reject(new Error('boom'))
      }
      resolve(42)
    })
  )

  hemera.add({
    topic: 'test',
    cmd: 'boom',
    fail: Joi.boolean().required(),
  }, function ({fail}, cb) {
    return asCallback(myPromise(fail), cb)
  })

  hemera.add({
    topic: 'test',
    cmd: 'boom2',
    fail: Joi.boolean().required(),
  }, function ({fail}) {
    return myPromise(fail)
  })

  // const cmd = 'boom'
  const cmd = 'boom2'

  hemera
    .act({ topic: 'test', cmd, fail: true })
    .then(x => hemera.log.info(x))
    .catch(e => console.log(e.stack))
})

Steps to Reproduce

  1. Clone https://github.com/pward123/hemera-add-promise-test.git
  2. cd hemera-add-promise-test
  3. yarn install
  4. npm start

Expected Result

The catch should immediately show a BusinessError

Actual Result

The console shows a deprecation warning for an unhandled promise rejection and the catch shows a Timeout error after the timeout expires.

Context

  • nats-hemera (core)
  • hemera-zipkin
  • hemera-store
  • hemera-stats
  • hemera-rabbitmq
  • hemera-nsq
  • hemera-arango-store
  • hemera-sql-store
  • hemera-elasticsearch
  • hemera-couchbase-store
  • hemera-mongo-store
  • hemera-joi
  • hemera-parambulator
  • hemera-msgpack
  • hemera-avro
  • hemera-redis-cache
  • hemera-jwt-auth

Your Environment

  • NATS: 0.7.20
  • Hemera: 2.1.0
  • NodeJs: 8.6.0
  • macos 10.12.6

client call code must in hemera.ready() method?

client call code must in hemera.ready() method?

hemera.ready(() => {
  hemera.act({
    topic: 'math',
    cmd: 'add',
    a: 1,
    b: 2
  }, function (err, resp) {
    this.log.info(resp, 'Result')
  })
})

client call can't as:

  hemera.act({
    topic: 'math',
    cmd: 'add',
    a: 1,
    b: 2
  }, function (err, resp) {
    this.log.info(resp, 'Result')
  })

directly?

microservice versioning

What would be the opinionated way on versioning the microservices? How to have 3-4 versions running side-by-side?

Pub/Sub Message not received after longer Timeout in Publisher

Description

I have built a simple PubSub example to play around and found the case that some published messages are not received by my receivers.

Steps to Reproduce

I was running my subscriber in 2 terminal Windows and my publisher in a third.

Subscriber Code

hemera.ready(function () {
  console.log('Ready')
  hemera.add({ topic: 'test', pubsub$: true }, function (resp) {
    console.log('Subscriber', process.pid, resp.value)
  })
})

Publisher Code

hemera.ready(function () {
  console.log('Ready')
  hemera.act({ topic: 'test', value: 1, pubsub$: true })
  hemera.act({ topic: 'test', value: 2, pubsub$: true })
  setTimeout(() => {
    console.log('After Timeout #1')
    hemera.act({ topic: 'test', value: 3, pubsub$: true })
    hemera.act({ topic: 'test', value: 4, pubsub$: true })
    setTimeout(() => {
      console.log('After Timeout #2')
      hemera.act({ topic: 'test', value: 5, pubsub$: true })
      hemera.act({ topic: 'test', value: 6, pubsub$: true })
      console.log('Closing')
      hemera.close()
    }, 3000)
  }, 30)
})

Expected Result

I would expect both subscribers to receive all 6 Messages

Actual Result

It seems that the subscribers only received the first 4 Messages
image

Although My Publisher seems to send all messages out:
Logs

[2017-07-01T16:59:57.682Z] INFO (hemera-m0rcs-Macbook.fritz.box-dc94a08f39f54e65b020ed3136591254/57743 on m0rcs-Macbook.fritz.box): Connected!
Ready
[2017-07-01T16:59:57.693Z] INFO (hemera-m0rcs-Macbook.fritz.box-dc94a08f39f54e65b020ed3136591254/57743 on m0rcs-Macbook.fritz.box): 
    outbound: {
      "id": "757d6b594e194d38a8da9df257edd876",
      "pattern": "topic:test,value:1"
    }
[2017-07-01T16:59:57.696Z] INFO (hemera-m0rcs-Macbook.fritz.box-dc94a08f39f54e65b020ed3136591254/57743 on m0rcs-Macbook.fritz.box): 
    outbound: {
      "id": "cbecbb5e42894b579870f34d363470db",
      "pattern": "topic:test,value:2"
    }
After Timeout #1
[2017-07-01T16:59:57.731Z] INFO (hemera-m0rcs-Macbook.fritz.box-dc94a08f39f54e65b020ed3136591254/57743 on m0rcs-Macbook.fritz.box): 
    outbound: {
      "id": "c05f8df426494d7396ceb5331207093c",
      "pattern": "topic:test,value:3"
    }
[2017-07-01T16:59:57.731Z] INFO (hemera-m0rcs-Macbook.fritz.box-dc94a08f39f54e65b020ed3136591254/57743 on m0rcs-Macbook.fritz.box): 
    outbound: {
      "id": "10d2558844b74025bab7a87f76928722",
      "pattern": "topic:test,value:4"
    }
After Timeout #2
[2017-07-01T17:00:00.737Z] INFO (hemera-m0rcs-Macbook.fritz.box-dc94a08f39f54e65b020ed3136591254/57743 on m0rcs-Macbook.fritz.box): 
    outbound: {
      "id": "3735272e43104f67895123e3a0750d63",
      "pattern": "topic:test,value:5"
    }
[2017-07-01T17:00:00.737Z] INFO (hemera-m0rcs-Macbook.fritz.box-dc94a08f39f54e65b020ed3136591254/57743 on m0rcs-Macbook.fritz.box): 
    outbound: {
      "id": "3b4ad509d8b34237a18a3f5e1d26051d",
      "pattern": "topic:test,value:6"
    }
Closing

Your Environment

  • NATS: 0.9.6
  • Hemera: 1.3.7
  • NodeJs: 6.6.0
  • Operating System and version: osx

[hemera-zipkin] Dependency graph not showing edges

Hi @sberryman I think I found the issue. There is something wrong with the annotations which are send to zipkin. This can take a while but I will fix it. Could you open an issue?

Based on what I saw last night you have an almost identical copy of seneca-zipkin-tracer including the zipkin-simple package.

From zipkin-simple:
Annotation Data contains additional info about the current method:

  • service: the name of the current service. It should be an identifier of running process (or class of processes), i.e.: web_server, background_worker, checkout_process. This will be displayed in the zipkin console
  • name: the name of the method being tracked, i.e.: POST /user or update_credentials. Thi will be displayed in the zipking console on the single span

Strange behaviour with nested act calls and timeout errors

Example code:

hemera.add({ topic : 'test', cmd : 'A' }, function(msg, reply) {
    console.log('A');
    setTimeout(() => reply(null, { ok : true }), 3000);
});

hemera.add({ topic : 'test', cmd : 'B' }, function(msg, reply) {

    console.log('B');
    this.act({ topic : 'test', cmd : 'A', timeout$ : 1000 }, function(err, res) {

       if ( err ) {
            console.log('A err');
            reply(err);
        } else {
            console.log('A res');
            reply(null, res);
        }

    });

});

hemera.act({ topic : 'test', cmd : 'B', timeout$ : 2000 }, (err, res) => {

    if ( err ) {
        console.log('B err');
    } else {
        console.log('B res');
    }

});

Output:

B
A
A err
B err
A res
B err

After the timeout, when the service replies with a response, the error gets forwarded to the first act call and not the response.
Expected output would be:

B
A
A err
B err
A res
B res

How can I create plugin with Typescript?

Here is my try:

const hp = require('hemera-plugin');

export class MongoExtend {
    public register: any = {
    };

    constructor() {

        this.register.attributes = {
            name: 'mongo-store-ext',
            description: 'Extend default mongo-store service',
            version: '1.0.0'
        };

        this.register.plugin = hp((options: any, next: any) => {
            console.log(this);
            next()
        });

        this.register.options = {}
    }


}

const mongoex = new MongoExtend;

hemera.use(mongoex.register);

But it doesn't work

It registers ok, but I don't get hemera instance inside plugin... Anyone know what is a problem?

An in-range update of pino is breaking the build 🚨

Version 3.0.2 of pino just got published.

Branch Build failing 🚨
Dependency pino
Current Version 3.0.1
Type dependency

This version is covered by your current version range and after updating it in your project the build failed.

As pino is a direct dependency of this project this is very likely breaking your project right now. If other packages depend on you it’s very likely also breaking them.
I recommend you give this issue a very high priority. I’m sure you can resolve this 💪


Status Details
  • coverage/coveralls First build on greenkeeper/pino-3.0.2 at 98.742% Details

  • continuous-integration/travis-ci/push The Travis CI build failed Details

Release Notes v3.0.2
Commits

The new version differs by 6 commits .

See the full diff.

Not sure how things should work exactly?

There is a collection of frequently asked questions and of course you may always ask my humans.


Your Greenkeeper Bot 🌴

[hemera-joi] Validate the whole pattern

Is it possible to validate the whole pattern using a custom function like in seneca-joi?
Example:

seneca.add({
    a: 1,
    joi$: function (schema) {
        return schema.keys({ b: Joi.required() })
    }
})

running within docker

Is there any limitation for running hemera microservices inside Docker? if so, what should be done as workarounds?

error TS2339: Property 'log' does not exist on type 'Hemera'.

Description

log missing in Hemera types although it exists.

Expected Result

no error

Actual Result

error TS2339: Property 'log' does not exist on type 'Hemera'.

Context

@types/nats-hemera

Your Environment

  • types/nats-hemera: 1.0.0
  • NodeJs: 8.4.0
  • Tyepescript: 2.5.2

How to integrate with Netflix Eureka?

Hi everyone,

I'm trying to choose a microservices framework to use with node
but I really need to be able to integrate it with Eureka since we already have a
microservices infrastructure using Eureka :'(

Does anybody know how to use hemera with Eureka for service register/discovery?

Allow setting store topic?

I notice that mongo-store topic is hard coding into the package. How about if I have multiple mongo stores in my services cluster?

Benchmarks

Hi Dustin

Have been following your project, and evaluating all alternatives for a project I am about to rewrite. Have you seen the results posted at https://github.com/icebob/microservices-benchmark?

Do you feel its a fair comparison?

Also I see you have files to do benchmarks, how do I run them?

Custom logging

How could I log additional data like trace$ or request$?
The context object is not passed to the logger

Multiple server versions

Hii,

Image if you have multiple servers on a NAT, spread by multiple version. What I want to know is, if there's any way to communicate to a specific server version using act command?

The logic behind that is, imagine you have two session servers (0.0.1 and 0.0.9). One specific application requests for something to session server this server depends on 0.0.9, so the request will reach to [email protected]. For some reason that server will crash and the request goes to the other server that is compatible with (ex. 0.0.1).

Thanks!

Publish to many queue group?

According to the docs, we can publish to many subscriber, or publish to only one queue group, but, how to publish to many queue group?

In other word, there are many roles listen to the same topic and react differently, but we wish to clustering a role with many instances, so, a publication should be pushed to all the subscriber roles, but only one instance of each role will receive it.

Cause: TypeError: Cannot read property 'type' of undefined

I cannot get any idea of what this error could be, can someone please point out what is the reason for it
Hapi Javascript Route plugin, I am using hapi-hemera plugin

'use strict';

const Joi = require('joi');
const Boom = require('boom');

const signupHandler = (request, reply) => {

  return reply.act({ topic: 'signup', cmd: 'register' },
    function (err, result) {
      return reply(err || result)
    })

};

const _routeConfig = {

  description: 'New xyz account signup.',
  notes: 'New xyz account signup.',
  tags: ['api', 'greeting'],
  validate: {
    payload: {
      company_name: Joi.string().required(),
      email: Joi.string().required(),
      first_name: Joi.string().required(),
      last_name: Joi.string().required(),
      mobile: Joi.string().required(),
      address: Joi.object({
        street: Joi.string().required(),
        city: Joi.string().required(),
        state: Joi.string().required(),
        zip: Joi.string().required(),
        country: Joi.string().required()
      }),
      coordinates: Joi.array().items(Joi.number().required(), Joi.number().required())
        .required()
    },
    headers: Joi.object({
    }).unknown()
  },
  pre: [],
  handler: signupHandler,
  auth: {
    strategy: 'auth0-xyz',
    mode: 'required'
  },
  plugins: {
    'hapi-swagger': {
      responses: {
        '200': {
          'description': 'Successfully completed signup process.'
        },
        '503': {
          'description': 'Error occured during signup process.'
        }
      }
    }
  }
};

module.exports = {
  routeConfig: _routeConfig
};

Worker Process Typescript module

import * as Hemera from 'nats-hemera'
import { Client, connect } from 'nats'

const authUrl = 'nats://localhost:4222'
const nats = connect(authUrl)
const hemera = new Hemera(nats, { logLevel: 'info' })

hemera.ready(() => {

  console.log('Ready to listen .. ')

  hemera.add({ topic: 'signup', cmd: 'register' }, (req: any, cb: any) => {

    console.log(JSON.stringify(req, null, 4))

    cb(null, 'req successful')
  })
})

export { hemera, nats, authUrl }

I am getting the following error

On Hapi Route

[2017-03-06T02:21:52.608Z] INFO (app/4624 on Mac-Pro.local): Connected!
Plugin registration and server initialization
  ✔ 5) should be successful (0 ms)
Signup Route
  ✔ 6) should be registered (6 ms)
[2017-03-06T02:21:52.645Z] INFO (app/4624 on Mac-Pro.local): ACT_OUTBOUND - ID:59507afe9e852550836ad49e070e50ca
[2017-03-06T02:21:52.661Z] INFO (app/4624 on Mac-Pro.local): ACT_INBOUND - ID:undefined (NaNms)
[2017-03-06T02:21:52.664Z] FATAL (app/4624 on Mac-Pro.local): Fatal error
    FatalError
        at self.sendRequest (/api-modules/signup/node_modules/nats-hemera/build/index.js:777:23)
        at Object.callback (/api-modules/signup/node_modules/hapi-hemera/node_modules/nats/lib/nats.js:1133:5)
        at Client.processMsg (/api-modules/signup/node_modules/hapi-hemera/node_modules/nats/lib/nats.js:892:11)
        at Client.processInbound (/api-modules/signup/node_modules/hapi-hemera/node_modules/nats/lib/nats.js:824:14)
        at Socket.<anonymous> (/api-modules/signup/node_modules/hapi-hemera/node_modules/nats/lib/nats.js:421:12)
        at emitOne (events.js:96:13)
        at Socket.emit (events.js:189:7)
        at readableAddChunk (_stream_readable.js:176:18)
        at Socket.Readable.push (_stream_readable.js:134:10)
        at TCP.onread (net.js:551:20)
    Cause: SyntaxError: Unexpected token o in JSON at position 1
        at JSON.parse (<anonymous>)
        at Object.exports.parse (/api-modules/signup/node_modules/errio/index.js:191:34)
        at Hemera.<anonymous> (/api-modules/signup/node_modules/nats-hemera/build/index.js:762:35)
        at done (/api-modules/signup/node_modules/items/lib/index.js:31:25)
        at Hemera.<anonymous> (/api-modules/signup/node_modules/nats-hemera/build/index.js:173:7)
        at each (/api-modules/signup/node_modules/nats-hemera/build/ext.js:51:11)
        at iterate (/api-modules/signup/node_modules/items/lib/index.js:36:13)
        at Object.exports.serial (/api-modules/signup/node_modules/items/lib/index.js:39:9)
        at Ext.invoke (/api-modules/signup/node_modules/nats-hemera/build/ext.js:54:11)
        at self.sendRequest (/api-modules/signup/node_modules/nats-hemera/build/index.js:741:48)
        at Object.callback (/api-modules/signup/node_modules/hapi-hemera/node_modules/nats/lib/nats.js:1133:5)
        at Client.processMsg (/api-modules/signup/node_modules/hapi-hemera/node_modules/nats/lib/nats.js:892:11)
        at Client.processInbound (/api-modules/signup/node_modules/hapi-hemera/node_modules/nats/lib/nats.js:824:14)
        at Socket.<anonymous> (/api-modules/signup/node_modules/hapi-hemera/node_modules/nats/lib/nats.js:421:12)
        at emitOne (events.js:96:13)
        at Socket.emit (events.js:189:7)
        at readableAddChunk (_stream_readable.js:176:18)
        at Socket.Readable.push (_stream_readable.js:134:10)
        at TCP.onread (net.js:551:20)

On Worker process

[2017-03-06T02:21:34.659Z] INFO (hemera-f1fa6cc7ea3438aa/4492 on Mac-Pro.local): Connected!
Ready to listen ..
[2017-03-06T02:21:34.670Z] INFO (hemera-f1fa6cc7ea3438aa/4492 on Mac-Pro.local): ADD - ADDED
[2017-03-06T02:21:52.656Z] ERROR (hemera-f1fa6cc7ea3438aa/4492 on Mac-Pro.local): Bad implementation
    ImplementationError
        at Hemera.onServerPreHandler (/worker-modules/signup/node_modules/nats-hemera/build/index.js:670:34)
        at done (/worker-modules/signup/node_modules/nats-hemera/build/extension.js:113:17)
        at Hemera.onServerPreHandler (/worker-modules/signup/node_modules/nats-hemera/build/extensions.js:129:3)
        at each (/worker-modules/signup/node_modules/nats-hemera/build/extension.js:75:16)
        at iterate (/worker-modules/signup/node_modules/nats-hemera/build/extension.js:118:11)
        at Function.serial (/worker-modules/signup/node_modules/nats-hemera/build/extension.js:121:9)
        at Extension.invoke (/worker-modules/signup/node_modules/nats-hemera/build/extension.js:81:17)
        at Hemera.onServerPreRequestHandler (/worker-modules/signup/node_modules/nats-hemera/build/index.js:711:47)
        at done (/worker-modules/signup/node_modules/nats-hemera/build/extension.js:113:17)
        at Hemera.onServerPreRequest (/worker-modules/signup/node_modules/nats-hemera/build/extensions.js:121:3)
    Cause: TypeError: Cannot read property 'type' of undefined
        at /worker-modules/signup/node_modules/nats-hemera/build/index.js:661:46
        at Function.serial (/worker-modules/signup/node_modules/nats-hemera/build/util.js:69:9)
        at Hemera.onServerPreHandler (/worker-modules/signup/node_modules/nats-hemera/build/index.js:648:26)
        at done (/worker-modules/signup/node_modules/nats-hemera/build/extension.js:113:17)
        at Hemera.onServerPreHandler (/worker-modules/signup/node_modules/nats-hemera/build/extensions.js:129:3)
        at each (/worker-modules/signup/node_modules/nats-hemera/build/extension.js:75:16)
        at iterate (/worker-modules/signup/node_modules/nats-hemera/build/extension.js:118:11)
        at Function.serial (/worker-modules/signup/node_modules/nats-hemera/build/extension.js:121:9)
        at Extension.invoke (/worker-modules/signup/node_modules/nats-hemera/build/extension.js:81:17)
        at Hemera.onServerPreRequestHandler (/worker-modules/signup/node_modules/nats-hemera/build/index.js:711:47)
[2017-03-06T02:21:52.663Z] FATAL (hemera-f1fa6cc7ea3438aa/4492 on Mac-Pro.local): process exited

Porposal: Support multiple databases conn by topic suffix

Some people have the requirement to access multiple databases with e.g mongo-store.
With the current solution, we can't provide it because we have to manage the connection by ourselves. There are many drivers which provide it out of the box but some don't.

Proposal:

We using the database name as a suffix for the topic name. This has the benefit that any service with a different database will create a new connection and act as a separate service in Hemera. You also can access the database with different db credentials. By the nature of NATS all requests are load balanced.

This is no replacement for a connection pool which managed the resources more intelligently.

// default
act({
  topic: 'mongo-store',
  cmd: 'find'
}, ...)
// with specific database
act({
  topic: 'mongo-store.db1',
  cmd: 'find'
}, ...)

The plugin registration should look like this

// default
hemera.use(hemeraMongo, {
  mongo: {
    url: 'mongodb://localhost:27017/db'
  }
})
// with specific database
hemera.use(hemeraMongo, {
  useDbAsTopicSuffix: true,
  database: 'db1',
  mongo: {
    url: 'mongodb://localhost:27017/db'
}
})

Roadmap 2.0

  • More natural and simple extensions lifecycle
  • Emit clientResponseError or serverResponseError only for middleware, extensions or fatal errors not when an error is replied by the user.
  • Remove support for generator functions
  • Remove async/await support in extensions due to performance and simplicity
  • Remove circuit breaker implementation
  • nexthas to be called explicit in the middleware
  • Calling send multiple times shouldn't have side effects
  • Don't abort request life cycle on business errors.
  • First replied error is set others are ignored
  • First replied value is sent others are ignored
  • Pass reply interface to add middlewares
  • Update all plugins to the new api
  • Use github releases for changelog informations
  • Update docs
  • Remove expose and use prototype based decorations
  • Use Avvio to bootstrap plugins asynchronously
  • Remove req.locals
  • Graceful shutdown routine as a separate plugin
  • Use prettier with standardjs linting rules

Plugin system is heavily inspired by https://github.com/fastify/fastify

Throw error when trying to extend a registered plugin

It's should not be possible to register a server method with a topic which is already used by a registered plugin. We have to guarantee that a plugin can be scaled alone.

E.g

use(mongodb) 
hemera.Add('topic:mongodb-store,cmd...') 

Act callback called twice on TimeoutError

If a timeout error occurs when a service is taking a longer time to respond the act callback is called twice. Once when the timeout error occurs and the second time when the service has finished the request:
Example:

hemera.add({ topic : 'test', cmd : 'timeout' }, (msg, reply) => {
    setTimeout(() => { reply(null, { ok : true }) }, 3000);
});

hemera.ready(() => {
	
    hemera.act({ topic : 'test', cmd : 'timeout', timeout$ : 1000 }, (err, res) => {
        console.log('done');
        console.log(err || res);
    });

});

Output:

done
{ TimeoutError
    at /home/andrija/Documents/hemera-test/node_modules/nats-hemera/build/index.js:949:21
    at Timeout._onTimeout (/home/andrija/Documents/hemera-test/node_modules/nats/lib/nats.js:1165:41)
    at ontimeout (timers.js:365:14)
    at tryOnTimeout (timers.js:237:5)
    at Timer.listOnTimeout (timers.js:207:5)
  message: 'Timeout',
  pattern: { topic: 'test', cmd: 'timeout', 'timeout$': 1000 } }
done
{ ok: true }

Provided examples for promises do not work

Hi ! Thanks for Hemera it is a great tool, but some examples do not work.

Description

Provided examples do not work. If you try examples provided with promises here:
https://github.com/hemerajs/hemera#what-hemera-code-looks-like
https://github.com/hemerajs/hemera/blob/master/examples/basic/async-await.js

Every time I obtain these errors:

[2017-07-28T08:44:32.701Z] INFO (hemera-CompanionCube-ab2674533b024d95b6b2bd1f31a473ab/26558 on CompanionCube): Connected!
[2017-07-28T08:44:34.712Z] ERROR (hemera-CompanionCube-ab2674533b024d95b6b2bd1f31a473ab/26558 on CompanionCube): Timeout
    TimeoutError
        at timeoutHandler (/home/remipassmoilesel/projects/poc-microservice-communications/node_modules/nats-hemera/lib/index.js:1283:21)
        at Timeout._onTimeout (/home/remipassmoilesel/projects/poc-microservice-communications/node_modules/nats/lib/nats.js:1242:5)
        at ontimeout (timers.js:469:11)
        at tryOnTimeout (timers.js:304:5)
        at Timer.listOnTimeout (timers.js:264:5)
[2017-07-28T08:44:34.713Z] ERROR (hemera-CompanionCube-ab2674533b024d95b6b2bd1f31a473ab/26558 on CompanionCube): Timeout
    TimeoutError
        at timeoutHandler (/home/remipassmoilesel/projects/poc-microservice-communications/node_modules/nats-hemera/lib/index.js:1283:21)
        at Timeout._onTimeout (/home/remipassmoilesel/projects/poc-microservice-communications/node_modules/nats/lib/nats.js:1242:5)
        at ontimeout (timers.js:469:11)
        at tryOnTimeout (timers.js:304:5)
        at Timer.listOnTimeout (timers.js:264:5)
(node:26558) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): TimeoutError: Timeout
(node:26558) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
^C[2017-07-28T08:54:32.016Z] FATAL (hemera-CompanionCube-ab2674533b024d95b6b2bd1f31a473ab/26558 on CompanionCube): process exited
    signal: "SIGINT"
[2017-07-28T08:54:32.018Z] INFO (hemera-CompanionCube-ab2674533b024d95b6b2bd1f31a473ab/26558 on CompanionCube): Gracefully shutdown

Steps to Reproduce

  1. Start NATS
  2. Past examples
  3. Install npm packages
  4. Run examples
  5. See errors

Context

  • nats-hemera (core)
  • hemera-joi

Your Environment

  • NATS: latest docker
  • Hemera: latest
  • NodeJs: 8.2
  • Operating System and version: Debian testing

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.