Moleculer: How to create multiple service broker with moleculer-runner?

Created on 24 Jan 2019  路  8Comments  路  Source: moleculerjs/moleculer

Hello , thank you very much for this awesome framework. My question is , how to create multiple broker with moleculer-runner?I dont want to create manually ServiceBroker, I want to use moleculer runner aproach. I mean moleculer.config.js exports 1 broker , how can I create multiple broker , and assign specific service to specific broker?

sorry for my english, have a nice day

The structure I want to achieve

|Node Instance A | Node Instance B |
| ------------- | ------------- |
| Broker A | Broker B |
| Service A1, Service A2 | Service B1, Service B2 |

Question

Most helpful comment

I see, it's a regular concept, but it doesn't mean that you can't use one repo. Check this example: https://github.com/moleculerjs/moleculer-examples/tree/master/blog
It's a repo which contains all services, so easy to develop because you starts all services locally.
In production, you can use Docker containers where you can separate services to multiple containers/node and they communicates each others via NATS transporter.

Here you can see you can define multiple services what you want to load on the nodes: https://github.com/moleculerjs/moleculer-examples/blob/master/blog/docker/mixed/docker-compose.yml#L34

All 8 comments

With parameters:

  • on NodeA: moleculer-runner services/a1.service.js services/a2.service.js
  • on NodeB: moleculer-runner services/b1.service.js services/b2.service.js

Or you can use env vars:

  • $ SERVICES=services/a1.service.js,services/a2.service.js moleculer-runner
  • $ SERVICES=services/b1.service.js,services/b2.service.js moleculer-runner

Thank you for your answer , so I understand that I should start nodes separately right? I am trying to understand concept. What is the correct way to start 2 or more Instance?
I created 2 seperate moleculer project template , start them separately with npm run dev
when I check nodes on moleculer-runner console , I cant see Node Instance B , also checked dcall command but it gave an error Service 'greeter.hello' is not found on 'B' node. , can you give us example please , thank you

Yes, if you want to start more brokers on the same node, you should start them separately. When I develop I'm using multiple terminals to start multiple brokers, so you have multiple console logs & REPL console and you can better detect the issues.
Are you trying on Windows? Because you can't start multiple "blocking" process with one command using &&. On linux you can use a simple & which doesn't wait for the process will be exited or use some external cli tool, like https://github.com/flesler/parallel

The other way is that you create only one project repo which contains all services. In development, you start all services with one broker but start them separately in production with SERVICES env var.

My target is ( and what I understand about concept) , run some services on one node instance and some services on other node instance and communicate with each other by brokers.
I am trying to assing single seperate nodes for each project but want them communicate with each other. Maybe I misunderstand of concept.

I see, it's a regular concept, but it doesn't mean that you can't use one repo. Check this example: https://github.com/moleculerjs/moleculer-examples/tree/master/blog
It's a repo which contains all services, so easy to develop because you starts all services locally.
In production, you can use Docker containers where you can separate services to multiple containers/node and they communicates each others via NATS transporter.

Here you can see you can define multiple services what you want to load on the nodes: https://github.com/moleculerjs/moleculer-examples/blob/master/blog/docker/mixed/docker-compose.yml#L34

Thank you very much its worked , and I understand the concept.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

rozhddmi picture rozhddmi  路  4Comments

ngraef picture ngraef  路  3Comments

slinkardbrandon picture slinkardbrandon  路  4Comments

Kamil93 picture Kamil93  路  3Comments

icebob picture icebob  路  3Comments