moleculer | : rocket : Progressive microservices framework for Node.js | Microservice library
kandi X-RAY | moleculer Summary
kandi X-RAY | moleculer Summary
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.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Register common metrics .
- Generates JSON schemas
- Wraps action middleware with hooks
- Updates the common metric metrics .
- Middleware for single Bulkhead
- Watch the files in the project
- Wrapper for bulk action requests .
- Wrapper function to make local action middleware
- Wrapper for tracing event handlers
- Wrapper around request middleware logic with retry logic
moleculer Key Features
moleculer Examples and Code Snippets
HelloWorld:
name: "serverless-moleculer-hello-world"
handler: handler.HelloWorld
memorySize: 256
timeout: 30
events:
- http:
path: /
method: any
cors:
origin: '*'
headers
const IO = require('socket.io')
const { ServiceBroker } = require('moleculer')
const SocketIOService = require('moleculer-io')
const broker = new ServiceBroker({
logger: console,
metrics:true,
validation: true
})
broker.createService({
name:
const moleculer = require('moleculer');
const { Service, Action } = require('moleculer-decorators');
// create new service factory, inheriting from moleculer native Service
class CustomService extends moleculer.Service {
constructor(broker, sche
Community Discussions
Trending Discussions on moleculer
QUESTION
I am in the process of implementing the backend for a business idea in moleculer microservice framework. It works quite well for now using the NATS transporter.
In the near future the number of messages will stay quite low (compared to this example in moleculer documentation) and scaling won't be an issue for now. Therefor In-Memory communication should not be an issue and I would like to remove the whole transporter overhead.
My motivation to use a microservice framework is loose coupling for a clean separation of responsibilities and the option to scale in the future with low effort.
Are there any major disadvantages in using the monolithic architecture for early stage projects or should I directly implement it as a "One service - one/multiple node(s)"-solution? The official documentation describes multiple architectures.
Any practical experience is highly appreciated!
...ANSWER
Answered 2022-Jan-12 at 13:54No, this is the biggest advantage of the Moleculer framework, that you can run all services on one node as a monolith while you have no big traffic. And if the traffic grows, you can start to separate the services into groups and make replicas if need (without modification in services codes).
QUESTION
I would like to display all my traces like in the examples from the moleculer-jaeger package:
But what i get is something like this: All spans you can see in this picture should be within the main trace (gateway).
Here is my moleculer.config:
...ANSWER
Answered 2021-Jun-14 at 21:33- This version already has a built-in jager tracer, see the documentation.
- In order for the events to be nested, it is necessary to transfer the context inside the actions, use
ctx.call
calls instead ofbroker.call
, so they will be nested. - To quickly receive support for the moleculer, join us in discord!
QUESTION
I have a moleculer-based microservice that has an endpoint which outputs a large JSON object (around tens of thousands of objects)
This is a structured JSON object and I know beforehand what it is going to look like.
...ANSWER
Answered 2021-May-15 at 05:57Are you asking for a general approach recommendation, or for support with the particular solution you have?
If it's for the first, then I think your best bet for communicating between the server and the client is through websockets, perhaps with something like Socket.io. A long lived connection will serve you well here, since it will take a long time to transmit all your data across.
Then you can send data from the server to the client any time you like. At that point you can read your data on the server as a node.js stream and emit the data one at a time.
The problem with using Oboe and writing to the response on every node is that it requires a long running response, and there's a high likelihood the connection could get interrupted before you've sent all the data across.
QUESTION
I get some JSON from a moleculer.js return call that looks like this:
...ANSWER
Answered 2021-Apr-23 at 08:05Turns out the easiest solution found so far (at the time of this writing) is to just re-parse the value string back into JSON and concatenate it into a new JSON.
Example code:
QUESTION
I'm using molecule for microservices. Actually I don't know how to expose the metrics port (3030) in the docker container to be able to read metrics from http://host:3030/metrics
when the app is executed ion my localhost it is working just fine but when deploying with docker-compose --build -up it don't work.
my docker compose traefik section ...ANSWER
Answered 2021-Mar-11 at 16:00Are you using Prometheus as exporter? If that's the case then please check https://github.com/AndreMaz/moleculer-prometheus-demo
QUESTION
I'm having trouble understanding the basic concept of MoleculerJS. I have a method called when a SQS message received.
...ANSWER
Answered 2021-Mar-15 at 20:45lifecycle methods don't have any input params meaning that you don't have context object by default.
However, you can use await this.broker.call("service.name", {data})
and call another service.
QUESTION
I have got this docker-compose.yaml. It defines 1 service with the public API and 4 services (replicated) with another two microservices each one (one receives events and another one saves info to mongo). This works perfectly when i do "docker-compose up". But I want to run each images with "docker run".
...ANSWER
Answered 2021-Feb-22 at 12:17Just set the env vars in docker run
, as well
E.g.
QUESTION
I am testing moleculer microservices framework to setting up an infraestructure. I will to use typescript (https://github.com/moleculerjs/moleculer-template-project-typescript). My idea is according the documentation is:
- create one project for with API Gateway => make doker => make k8s deployment with N replicas
- create 1 project per microservice => dockerize => make k8s deployment with N replicas
- create 2 project per microservice => dockerize => make k8s deployment with N replicas ...
- create N project per microservice => dockerize => make k8s deployment with N replicas
I will use redis as transporter. I want to use redis also in development.
I have got this doubt, because you can create in the same project all the microservices, but in this way, you are developing a monolitic application (and only in one thread). I think that you need to sepparate each microservice in independent (typescripts) projects to make it after docker images and the make pods in k8s in the deployment phase.
...ANSWER
Answered 2021-Feb-19 at 10:04You can separate every microservices into a separated projects, but with Moleculer you don't need it. You can put all services into one project. The development will be easy and fast, and at deploying you can control which services will be loaded. So you can generate one docker image and control the loaded services with environment variables.
E.g here you can see the SERVICES
env var in docker-compose.yml:
https://moleculer.services/docs/0.14/deploying.html#Docker-Compose
QUESTION
I am using moleculerjs to handle microservices on the backend, and with one of the front-end applications I am handling the communication over sockets. To do that I am using moleculer.io
. The problem I'm running into is that, even though I am attaching the socket to ctx
in the onBeforeCall()
hook, the socket is not there when I console.log ctx
in the controller function.
My gateway looks like this (notice the socket is being added to the ctx
object in the onBeforeCall()
hook:
ANSWER
Answered 2021-Feb-12 at 14:01You can't do that. You can't put anything to the ctx
. The ServiceBroker will serialize & transfer only the ctx.params
and ctx.meta
properties. But you can't put the socket into them because the Socket object what you like is not serializable, so you can't access it in remote services. It can work in a monolith project, not in a microservices project.
QUESTION
My problem is that I need to increase max_payload value that NATS receive but I have no idea where I can do it.
The project is using Moleculer and NATS is created as a container with docker.
When I try to make a request which is bigger than 1MB NATS returns:
...ANSWER
Answered 2021-Jan-09 at 09:08You should create a configuration file for NATS. And push it to the container as a Docker volume and set the command
as -c nats-server.conf
nats-server.conf
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install moleculer
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page