Moleculer
Moleculer is a fast, modern and powerful microservices framework for Node.js. It helps you to build efficient, reliable & scalable services. Moleculer provides many features for building and managing your microservices.
Website: https://moleculer.services
Documentation: https://moleculer.services/docs
What's included
- Promise-based solution (async/await compatible)
- request-reply concept
- support event driven architecture with balancing
- built-in service registry & dynamic service discovery
- load balanced requests & events (round-robin, random, cpu-usage, latency, sharding)
- many fault tolerance features (Circuit Breaker, Bulkhead, Retry, Timeout, Fallback)
- plugin/middleware system
- support versioned services
- support Streams
- service mixins
- built-in caching solution (Memory, MemoryLRU, Redis)
- pluggable loggers (Console, File, Pino, Bunyan, Winston, Debug, Datadog, Log4js)
- pluggable transporters (TCP, NATS, MQTT, Redis, NATS Streaming, Kafka, AMQP 0.9, AMQP 1.0)
- pluggable serializers (JSON, Avro, MsgPack, Protocol Buffer, Thrift)
- pluggable parameter validator
- multiple services on a node/server
- master-less architecture, all nodes are equal
- parameter validation with fastest-validator
- built-in metrics feature with reporters (Console, CSV, Datadog, Event, Prometheus, StatsD)
- built-in tracing feature with exporters (Console, Datadog, Event, Jaeger, Zipkin)
- official API gateway, Database access and many other modules...
Installation
$ npm i moleculer --save
or
$ yarn add moleculer
Create your first microservice
This example shows you how to create a small service with an add
action which can add two numbers and how to call it.
const { ServiceBroker } = require("moleculer");
const broker = new ServiceBroker();
broker.createService({
name: "math",
actions: {
add(ctx) {
return Number(ctx.params.a) + Number(ctx.params.b);
}
}
});
broker.start()
.then(() => broker.call("math.add", { a: 5, b: 3 }))
.then(res => console.log("5 + 3 =", res))
.catch(err => console.error(`Error occurred! ${err.message}`));
Try it in your browser
Create a Moleculer project
Use the Moleculer CLI tool to create a new Moleculer based microservices project.
-
Create a new project (named moleculer-demo
)
$ npx moleculer init project moleculer-demo
-
Open project folder
$ cd moleculer-demo
-
Start project
$ npm run dev
-
Open the http://localhost:3000/ link in your browser. It shows a welcome page which contains many information about your project & you can test the generated services.
:tada: Congratulations! Your first Moleculer-based microservices project is created. Read our documentation to learn more about Moleculer.
Official modules
We have many official modules for Moleculer. Check our list!
Supporting
Moleculer is an open source project. It is free to use for your personal or commercial projects. However, developing it takes up all our free time to make it better and better on a daily basis. If you like Moleculer framework, please support it.
Thank you very much!
For enterprise
Available as part of the Tidelift Subscription.
The maintainers of moleculer and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open source dependencies you use to build your applications. Save time, reduce risk, and improve code health, while paying the maintainers of the exact dependencies you use. Learn more.
Documentation
You can find here the documentation.
Changelog
See CHANGELOG.md.
Security contact information
To report a security vulnerability, please use the Tidelift security contact.
Tidelift will coordinate the fix and disclosure.
Contributions
We welcome you to join to the development of Moleculer. Please read our contribution guide.
License
Moleculer is available under the MIT license.
3rd party licenses
Contact
Copyright (c) 2016-2020 MoleculerJS
0.14.0 (2020-02-12)
Migration guide from 0.13 to 0.14
Breaking changes
Minimum Node version is 10
The Node version 8 LTS lifecycle has been ended on December 31, 2019, so the minimum required Node version is 10.
Bluebird dropped
The Bluebird Promise library has been dropped from the project because as of Node 10 the native Promise
implementation is faster (2x) than Bluebird.
Nonetheless, you can use your desired Promise library, just set the Promise
broker options.
Using Bluebird
const BluebirdPromise = require("bluebird");
// moleculer.config.js
module.exports = {
Promise: BluebirdPromise
};
Please note, the given Promise library will be polyfilled with delay
, method
, timeout
and mapSeries
methods (which are used inside Moleculer core modules).
Communication protocol has been changed
The Moleculer communication protocol has been changed. The new protocol version is 4
.
It means the new Moleculer 0.14 nodes can't communicate with old <= 0.13 nodes.