Breaking changes
Protocol changed #86
The Moleculer transportation protocol has been changed. It means, the new (>= v0.11) versions can't communicate with the old (<= v0.10.x) ones.
You can find more information about changes in #86 issue.
Balanced events
The whole event handling has been rewritten. By now Moleculer supports event driven architecture. It means that event emits are balanced like action calls are.
For example, you have 2 main services: users
& payments
. Both subscribe to the user.created
event. You start 3 instances from users
service and 2 instances from payments
service. If you emit the event with broker.emit('user.created')
, broker groups & balances the event, so only one users
and one payments
service receive the event.
You can also send broadcast events with the broker.broadcast('user.created
) command. This way every service instance on every node receives the event.
The broker.broadcastLocal('user.created')
command sends events only to the local services.
Renamed & new internal events
Every internal event name starts with '$'. These events are not transferred to remote nodes.
Renamed events:
node.connected
->$node.connected
node.updated
->$node.updated
node.disconnected
->$node.disconnected
services.changed
->$services.changed
. It is called if local or remote service list is changed.circuit-breaker.closed
->$circuit-breaker.closed
circuit-breaker.opened
->$circuit-breaker.opened
circuit-breaker.half-opened
->$circuit-breaker.half-opened
New events:
- global circuit breaker events for metrics:
metrics.circuit-breaker.closed
,metrics.circuit-breaker.opened
,metrics.circuit-breaker.half-opened
Switchable built-in load balancer
The built-in Moleculer load balancer is switchable. You can turn it off, if the transporter has internal balancer (currently AMQP has it).
const broker = new ServiceBroker({
disableBalancer: false
});
Please note! If built-in balancer is disabled, every call & emit (including local ones too) are transferred via transporter.
Removed broker methods
Some internal broker methods have been removed or renamed.
broker.bus
has been removed.broker.on
has been removed. Useevents
in service schema instead.broker.once
has been removed.broker.off
has been removed.broker.getService
has been renamed tobroker.getLocalService
broker.hasService
has been removed.broker.hasAction
has been removed.broker.getAction
has been deprecated.broker.isActionAvailable
has been removed.
Changed local service responses
Internal action ($node.list
, $node.services
, $node.actions
, $node.health
) responses are changed. New internal action ($node.events
) to list event subscriptiion is added.
Broker option changes
heartbeatInterval
default value is changed from10
to5
.heartbeatTimeout
default value is changed from30
to15
.circuitBreaker.maxFailures
default value is changed from5
to3
.logFormatter
accepts string. Thesimple
value is a new formatter to show only log level & log messages.
New
Ping command
New PING & PONG feature has been implemented. Ping remite nodes to measure the network latency and system time differences.
broker.createService({
name: "test",
events: {
"$node.pong"({ nodeID, elapsedTime, timeDiff }) {
this.logger.info(`Pong received from '${nodeID}' - Time: ${elapsedTime}ms, System time difference: ${timeDiff}ms`);
}
}
});
broker.start().then(() => broker.transit.sendPing(/*nodeID*/));
Pluggable validator
The Validator in ServiceBroker is plugable. So you can change the built-in fastest-validator
to a slower one :) Example Joi validator
Waiting for other services feature
If your services depend on other ones, use the waitForService
method to make services wait until dependencies start.
let svc = broker.createService({
name: "seed",
started() {
return this.waitForServices(["posts", "users"]).then(() => {
// Do work...
});
}
});
Signature:
this.waitForServices(serviceNames: String|Array<String>, timeout: Number/*milliseconds*/, interval: Number/*milliseconds*/): Promise
New error types
We added some new Moleculer error classes.
MoleculerRetryableError
- Common Retryable error. Caller retries the request ifretryCount > 0
.MoleculerServerError
- Common server error (5xx).MoleculerClientError
- Common client/request error (4xx).ServiceNotAvailable
- Raises if the service is registered but isn't available (no live nodes or CB disabled them).ProtocolVersionMismatchError
- Raises if connect a node with an older client (<= v0.10.0)).
Other changes
- The cachers don't listen "cache.clean" event.