The Moleculer has a built-in service registry module. It stores all information about services, event listeners and nodes. When you call a service or emit an event, broker asks the registry to look up a node which executes the given service.
You can access the stored data via internal service.
If a service has multiple running instances, Registry uses strategies to select a node from all available nodes. There are some built-in strategies, or you can create your custom strategies too.
ServiceBroker can resolve the
strategy from a string or set a
BaseStrategy class to the
This strategy selects a node based on RoundRobin algorithm.
This strategy selects a node randomly.
This strategy selects a node which has the lowest CPU usage. Due to the node list can be very long, it gets samples and selects the node with the lowest CPU usage from only samples instead of the whole node list.
||the number of samples.|
||the low CPU usage percent (%). The node which has lower CPU usage than this value is selected immediately.|
Usage with custom options