Moleculer v0.14.14 Release Notes
Release Date: 2021-06-27 // almost 3 years ago-
105 commits from 11 contributors.
๐ New CBOR serializer #905
CBOR (cbor-x) is a new serializer but faster than any other serializers.
Example
// moleculer.config.js module.exports = { logger: true, serializer: "CBOR" };
Benchmark
Suite: Serialize packet with 10bytes โ JSON 509,217 rps โ Avro 308,711 rps โ MsgPack 79,932 rps โ ProtoBuf 435,183 rps โ Thrift 93,324 rps โ Notepack 530,121 rps โ CBOR 1,016,135 rps JSON (#) 0% (509,217 rps) (avg: 1ฮผs) Avro -39.38% (308,711 rps) (avg: 3ฮผs) MsgPack -84.3% (79,932 rps) (avg: 12ฮผs) ProtoBuf -14.54% (435,183 rps) (avg: 2ฮผs) Thrift -81.67% (93,324 rps) (avg: 10ฮผs) Notepack +4.11% (530,121 rps) (avg: 1ฮผs) CBOR +99.55% (1,016,135 rps) (avg: 984ns)
settled
option inbroker.mcall
The
broker.mcall
method has a newsettled
option to receive all Promise results. Without this option, if you make a multi-call and one call is rejected, the response will be a rejectedPromise
and you don't know how many (and which) calls were rejected.If
settled: true
, the method returns a resolvedPromise
in any case and the response contains the statuses and responses of all calls.Example
const res = await broker.mcall([ { action: "posts.find", params: { limit: 2, offset: 0 }, { action: "users.find", params: { limit: 2, sort: "username" } }, { action: "service.notfound", params: { notfound: 1 } } ], { settled: true }); console.log(res);
The
res
will be something similar to[ { status: "fulfilled", value: [/*... response of `posts.find`...*/] }, { status: "fulfilled", value: [/*... response of `users.find`...*/] }, { status: "rejected", reason: {/*... Rejected response/Error`...*/} } ]
๐ New
MOLECULER_CONFIG
environment variable in Runner๐ง In the Moleculer Runner, you can configure the configuration filename and path with the
MOLECULER_CONFIG
environment variable. It means, no need to specify the config file with--config
argument.๐ Supporting
[email protected]
in NATS transporter๐ The new nats
2.x.x
version has a new breaking API which has locked the NATS transporter for[email protected]
library. As of this release, the NATS transporter supports both major versions of thenats
library.The transporter automatically detects the version of the library and uses the correct API.
๐ Async custom validator functions and
ctx
as metadata๐ Since
[email protected]
, the FastestValidator supports async custom validators and you can pass metadata for custom validator functions. ๐ In Moleculer, theFastestValidator
passes thectx
as metadata. It means you can access to the current context, service, broker and you can make async calls (e.g calling another service) in custom checker functions.Example
// posts.service.js module.exports = { name: "posts", actions: { params: { $$async: true, owner: { type: "string", custom: async (value, errors, schema, name, parent, context) => { const ctx = context.meta; const res = await ctx.call("users.isValid", { id: value }); if (res !== true) errors.push({ type: "invalidOwner", field: "owner", actual: value }); return value; } }, }, /* ... */ } }
๐ Changes
- ๐ fix node crash in encryption mode with TCP transporter. #849
- ๐ฆ expose
Utils
in typescript definition. #909 - other d.ts improvements. #920, #922, #934, #950
- ๐ fix etcd3 discoverer lease-loss issue #922
- catch errors in Compression and Encryption middlewares. #850
- using optional peer dependencies. #911
- โ add relevant packet to to serialization and deserialization calls. #932
- ๐ fix disabled balancer issue with external discoverer. #933