Minimum Node version is 10 (BREAKING)
The Node version 8 LTS lifecycle has been ended on December 31, 2019, so the minimum required Node version is 10.
Bluebird dropped (BREAKING)
The Bluebird Promise library has been dropped from the project because as of Node 10 the native Promise
implementation is faster (2x) than Bluebird.
Nonetheless, you can use your desired Promise library, just set the Promise
broker options.
Using Bluebird
const BluebirdPromise = require("bluebird");
// moleculer.config.js
module.exports = {
Promise: BluebirdPromise
};
Please note, the given Promise library will be polyfilled with
delay
,method
,timeout
andmapSeries
methods (which are used inside Moleculer core modules).
Better service event handler testing
Service class has a new emitLocalEventHandler
method in order to call a service event handler directly. It can be useful in Unit Tests because you don't need to emit an event with broker.emit
.
Example
// posts.service.js
module.exports = {
name: "posts",
events: {
async "user.created"(ctx) {
this.myMethod(ctx.params);
}
}
};
// posts.service.spec.js
describe("Test events", () => {
const broker = new ServiceBroker({ logger: false });
const svc = broker.createService(PostService);
beforeAll(() => broker.start());
afterAll(() => broker.stop());
describe("Test 'user.created' event", () => {
beforeAll(() => svc.myMethod = jest.fn());
afterAll(() => svc.myMethod.mockRestore());
it("should call the event handler", async () => {
await svc.emitLocalEventHandler("branch.closed", { a: 5 });
expect(svc.myMethod).toBeCalledTimes(1);
expect(svc.myMethod).toBeCalledWith({ a: 5 });
});
});
});
Stream objectMode
support
Thanks for @artur-krueger, the request & response streams support objectMode
, as well. You can also send Javascript objects via streams.
Example
Other changes
- In metrics, the
defaultBuckets
value has been changed to milliseconds. - add
caller
label for EVENT_RECEIVED_TOTAL metric. - the heartbeat logic can be disabled by
heartbeatInterval: 0
broker option. - remove the new
currentContext
property inService
&ServiceBroker
. - in Service instances the original schema (before applying mixins) is available via
this.originalSchema
.