Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Send events even if no service is registered in the Service Registry #426

Closed
mathiasmoeller opened this issue Nov 29, 2018 · 5 comments
Closed

Comments

@mathiasmoeller
Copy link

mathiasmoeller commented Nov 29, 2018

Is your feature request related to a problem? Please describe.
I am building a system of micro services that broadcast events. One of the services will be a Moleculer service.
Even with disableBalancer: true Moleculer will only publish events to the transporter (NATS in my case) if another Moleculer service is registered in the Service Registry of Moleculer. If not no events will be broadcasted.
If you use Moleculer together with other frameworks they will not receive any events unless one of them is a Moleculer service.

Describe the solution you'd like
It would be great to have an option that forces Moleculer to send events to the transporter no matter if another service is registered in the Service Registry or not. This is crucial to be able to use Moleculer in an diverse micro service environment.

I created a small project to show the issue:
https://github.com/mathiasmoeller/moleculer-publish-subscribe-demo

@icebob
Copy link
Member

icebob commented Nov 29, 2018

The problem is here:

if (groups.length == 0)
return;

But there are other problems too. The broker.broadcast doesn't work correctly with disableBalancer option.

@icebob
Copy link
Member

icebob commented Dec 3, 2018

Hi mathias,

The broker.emit works just you should use groups always.
E.g.

broker.start().then(() => {
    setInterval(() => {
        broker.emit("test.event", { ddata: "this is test data" }, ["group"]);
    }, 2000);
});


nats.subscribe("MOL.EVENTB.group.test.event", { queue: "group" }, message => {
    broker.logger.info("nodejs-subscriber: Test event received with payload:", message);
});

I will fix the broker.broadcast too, but I can't do this with broker.call. The action calling is very different. The broker always looks up the action definition from registry. And it is not easy to skip this parts.

@mathiasmoeller
Copy link
Author

Thanks! I will try this approach ASAP.

@mathiasmoeller
Copy link
Author

It seems to work! Thanks a lot. Should I leave my demo project public so you can use it to test the broker.broadcast issue?

@icebob
Copy link
Member

icebob commented Dec 5, 2018

Not need it. I've created a simple dev example to demonstrate it: https://github.com/moleculerjs/moleculer/blob/fix-426/dev/no-balancer.js

@icebob icebob mentioned this issue Dec 8, 2018
11 tasks
@icebob icebob closed this as completed May 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants