Coder Social home page Coder Social logo

hemera's Introduction

Hemera

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

A Node.js microservices toolkit for the NATS messaging system

📓 Getting Started

Hemera (/ˈhɛmərə/; Ancient Greek: Ἡμέρα [hɛːméra] "day") is a small wrapper around the 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 add the same add as many as you want on different hosts to ensure maximal availability. The only dependency you have is a single binary of 7MB. Mind your own business NATS do the rest for you:

The key features of NATS in combination with Hemera are:

  • Lightweight: The Hemera core is small as possible and can be extended by extensions or plugins.
  • 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: Providing 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) e.g. topic:auth:germany. Queue group name allow load balancing of services.
  • 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 the signatures of your 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: Any distributed system need good tracing capabilities. We provide support for Zipkin a tracing system which manages both the collection and lookup of this data.
  • Monitoring: Your NATS server can be monitored by cli or a dashboard.
  • Payload validation: Create your own validator or use existing plugins for Joi and Parambulator.
  • Serialization: Use JSON, Msgpack or Avro to serialize your data (dynamic or static).
  • Metadata: Transfer metadata across services or attach contextual data to tracing systems.
  • Dependencies: NATS is a single binary of 7MB and can be deployed in seconds.
  • Typescript: We provide a definition file to support auto-intellisense.

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).

What Hemera code looks like

We support:

  • Async/Await (Node 7.6+)
  • Promise
  • Error-first-callback style
const Hemera = require('nats-hemera')
const HemeraJoi = require('hemera-joi')
const nats = require('nats').connect()

const hemera = new Hemera(nats, { logLevel: 'info' })
hemera.use(HemeraJoi)

hemera.ready(async () => {

  hemera.setOption('payloadValidator', 'hemera-joi')
  let Joi = hemera.joi

  hemera.add({ 
    topic: 'math',
    cmd: 'add',
    a: Joi.number().required(),
    b: Joi.number().required()
  }, async function (req) {
    return await req.a + req.b
  })

  const a = hemera.act({ topic: 'math', cmd: 'add', a: 10, b: 30 })
  const b = hemera.act({ topic: 'math', cmd: 'add', a: 10, b: 60 })

  const result = await Promise.all([a, b])
  hemera.log.info(result)

})

Documentation

Who's using Hemera?

appcom-interactive amerbank
appcom interactive amerbank

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

Be aware of your requirements

Hemera has not been designed for high performance on a single process. It has been designed to create lots of microservices doesn't matter where they live. It choose simplicity and reliability as primary goals. It act together with NATS as central nervous system of your distributed system. Transport independency was not considered to be a relevant factor. In addition we use pattern matching which is very powerful. The fact that Hemera needs a broker is an argument which should be taken into consideration when you compare hemera with other frameworks. The relevant difference between microservice frameworks like senecajs, molecurer is not the performance or modularity its about the complexity you need to manage. Hemera is expert in providing an interface to work with lots of services in the network, NATS is the expert to deliver the message at the right place. Hemera is still a subscriber of NATS with some magic in routing and extensions. We don't have to worry about all different aspects in a distributed system like routing, load-balancing, service-discovery, clustering, health-checks ...

Characteristics

  • Max payload size 1MB but it's configurable in NATS Server
  • Messages are delivered at-most-once
  • SSL Support
  • Rely on a publish-subscribe (pub/sub) distribution model
  • Cluster support
  • Do you need reliable message delivery ? Look at hemera-nats-streaming

Packages

The hemera repo is managed as a monorepo, composed of multiple npm packages.

General Version
nats-hemera npm
hemera-plugin npm
hemera-store npm
hemera-stats npm
hemera-controlplane npm
hemera-cli npm
hemera-mail npm
hemera-slackbot npm
hemera-graceful-shutdown npm
Tracer Version
hemera-zipkin npm
hemera-jaeger npm
Messaging bridges Version
hemera-nats-streaming npm
hemera-rabbitmq npm
hemera-nsq npm
hemera-web npm
hemera-sqs npm
Database adapter Version
hemera-arango-store npm
hemera-sql-store npm
hemera-elasticsearch npm
hemera-couchbase-store npm
hemera-mongo-store npm
hemera-rethinkdb-store npm
Payload validation Version
hemera-joi npm
hemera-parambulator npm
Data serialization Version
hemera-msgpack npm
hemera-avro npm
Data compression Version
hemera-snappy npm
Cache Version
hemera-redis-cache npm
Granting / Authenticating Version
hemera-jwt-auth npm

Performance

Platform info:
==============
   Windows_NT 10.0.15063 x64
   Node.JS: 8.4.0
   V8: 6.0.286.52
   Intel(R) Core(TM) i5-6600K CPU @ 3.50GHz × 4
==============
.\benchmark\request_rt.js
22436 request-responses/sec
Avg roundtrip latency: 22 microseconds

.\benchmark\request_rt_async_await.js
22002 request-responses/sec
Avg roundtrip latency: 22 microseconds

Changelog

See Releases

Contributing

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

Versioning

We use SemVer for versioning. Available versions tags on this repository.

Authors

See also the list of contributors who participated in this project.

License

This project is licensed under the MIT License - see the LICENSE file for details

Inspiration

Seneca - A microservices toolkit for Node.js.

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

Support / Donate

We prefer a PR but if you have no time but want to give us something back you can support us with a starbucks coffee PaypalMe

hemera's People

Contributors

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

Watchers

James Cloos avatar  avatar

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.