Scalability
Scalability
Any subscription is managed by NATS. You don't need any service discovery. Total location transparency.
Fault tolerance
Fault tolerance
Auto-heals when new services are added. Configure cluster mode to increase reliability.
Plugins
Plugins
Providing reliable and modern plugins to the community e.g for RabbitMQ, Jaeger, Mongodb, Arangodb or Elasticsearch.
Extensible
Extensible
Hook into the server or client lifecycle with the help of extensions. Use middlewares or the validation library of your choice.
Load Balancing
Load Balancing
Requests are load balanced (random) by NATS mechanism of "queue groups".
Pattern driven
Pattern driven
Define the signatures of your RPC's in JSON and use the flexibility of pattern-matching.
Metadata
Metadata
Transfer metadata across services or attach contextual data to tracing systems.
Serialization
Serialization
Use custom serializer e.g MessagePack.
Give it a try
Install NATS Client and Hemera
npm install nats nats-hemera
Install NATS Server
# Download NATS
https://nats.io/download/
# Start
./gnatsd
Example
const Hemera = require('nats-hemera')
const HemeraJoi = require('hemera-joi')
const nats = require('nats').connect()
const hemera = new Hemera(nats, {
logLevel: 'info'
})
// set payload validator of your choice
hemera.use(HemeraJoi)
const start = async () => {
try {
// establish connection and bootstrap hemera
await hemera.ready()
// use exposed lib from plugin
let Joi = hemera.joi
// define your first server action
hemera.add(
{
topic: 'math',
cmd: 'add',
a: Joi.number().required(),
b: Joi.number().required()
},
async function(req) {
return req.a + req.b
}
)
hemera.log.info('service listening')
// start first request
let response = await hemera.act({
topic: 'math',
cmd: 'add',
a: 10,
b: 10
})
hemera.log.info(response.data)
// keep the parent "context" to retain meta and trace informations
response = await response.context.act({
topic: 'math',
cmd: 'add',
a: 10,
b: 10
})
hemera.log.info(response.data)
} catch (err) {
hemera.log.error(err)
process.exit(1)
}
}
start()
What is Hemera?
What is Hemera?
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. 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 will do the rest for you.
What is NATS?
Be aware of your requirements
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, moleculer 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 ...