Closed ColonelBundy closed 1 year ago
Good idea, but maybe need a better method name. For me the publish
doesn't mean this logic.
@icebob How about broker.emit
instead?
broker.emit
is already in use. Maybe just extend options (third parameter) for broker.broadcast
by adding something like this:
broker.broadcast("user.created", { user }, {
groups: ["user", "purchase"],
skipSelf: true
});
@quex46 Good idea. And it is flexible.
@quex46 right, forgot about that one. skipSelf
sounds good!
Is there somebody to implement the first proposal?
@ColonelBundy for 2nd proposal: I think no need a new function. It can be merged to the first proposal. E.g:
broker.broadcast("user.created", { user }, {
nodeID: "node-123",
groups: ["user", "purchase"]
});
I was under the impression that the current code already skips the current node: https://github.com/moleculerjs/moleculer/blob/f6ac90bcd128ded3bacd8220e1ddae97b0e0ce6e/src/service-broker.js#L1288
UPDATED!
broker.broadcast
A proposal to modify
broker.broadcast
method, to allow a node to broadcast to all nodes except itself. This can be done adding a key calledskipSelf
Example: (thanks, @quex46)
broker.send
To further extend the functionality of the event system, how about a
broker.send
as well? it would take an event name, data, nodeID and optionally a group. This would allow a node to reply to another node, reasoning by keeping the group would be to better support mixin isolation.Example:
UPDATED
Thoughts?