I would like to announce that as the outcome of a half year’s hard work I created a brand-new microservices framework for NodeJS.
What is Moleculer?
Moleculer is an open-source fast & flexible framework, licensed under MIT. It contains most of all important microservices features (service registry, auto-discovery, load balancing, circuit-breaker…etc).
- Promise-based solution (with Bluebird)
- request-reply concept
- support event driven architecture with balancing
- supports middlewares
- built-in caching solution (memory, Redis)
- pluggable transporters (TCP, NATS, MQTT, Redis, AMQP, NATS Streaming, Kafka)
- pluggable serializers (JSON, Avro, MsgPack, Protocol Buffer)
- load balanced requests (round-robin, random)
- auto discovery services
- health monitoring, metrics & statistics
Moleculer is available as an npm package. You can install it with npm or yarn
$ npm install moleculer
This simple example show you how easy it is to create a service in Moleculer and call it.
As you can see above, we created a
math service which has an
addaction. This action is able to add two numbers, the values of “a” and “b” parameters. After it created, we can call it with the
broker.call method. The first parameter is the calling path (service name + action name), the second parameter is the params which is passed to the action handler wrapped to a Context object.
You can try it in your browser on Runkit!
Create a project
Use the Moleculer CLI tool to create a new Moleculer based microservices project.
- Install moleculer-cli globally
npm install moleculer-cli -g
2. Create a new project (named
moleculer init project moleculer-demo
Press Yes on all questions.
3. Open project folder and start it
npm run dev
4. Open the http://localhost:3000/api/greeter/hello link in your browser. It will call the
hello action of
5. Open the http://localhost:3000/api/greeter/welcome?name=world link to call the
welcome action of
Congratulations! You have just created your first Moleculer based microservices project. Welcome to the microservices world!