moleculer

Progressive microservices framework for Node.js

MIT License

Downloads
187.9K
Stars
6K
Committers
147

Bot releases are hidden (Show)

moleculer - v0.14.33 Latest Release

Published by icebob 7 months ago

What's Changed

New Contributors

Full Changelog: https://github.com/moleculerjs/moleculer/compare/v0.14.32...v0.14.33

moleculer - v0.14.32

Published by icebob 11 months ago

What's Changed

New Contributors

Full Changelog: https://github.com/moleculerjs/moleculer/compare/v0.14.31...v0.14.32

moleculer - v0.14.31

Published by icebob about 1 year ago

What's Changed

New Contributors

Full Changelog: https://github.com/moleculerjs/moleculer/compare/v0.14.30...v0.14.31

moleculer - v0.14.30

Published by icebob over 1 year ago

What's Changed

New Contributors

Full Changelog: https://github.com/moleculerjs/moleculer/compare/v0.14.29...v0.14.30

moleculer - v0.14.29

Published by icebob over 1 year ago

What's Changed

New Contributors

Full Changelog: https://github.com/moleculerjs/moleculer/compare/v0.14.28...v0.14.29

moleculer - v0.14.28

Published by icebob almost 2 years ago

What's Changed

  • fix no clean exit on shutdown, with disableBalancer: true #1168
  • change __proto__ to Object.getProtoTypeOf #1170
  • fix merge schemas (handling nulls) #1172
  • fix hot reload error handling #1174
  • update d.ts file
  • update dependencies

New Contributors

Full Changelog: https://github.com/moleculerjs/moleculer/compare/v0.14.27...v0.14.28

moleculer - v0.14.27

Published by icebob almost 2 years ago

What's Changed

New Contributors

Full Changelog: https://github.com/moleculerjs/moleculer/compare/v0.14.26...v0.14.27

moleculer - v0.14.26

Published by icebob almost 2 years ago

What's Changed

Changes

  • fix typescript definitions for the Service class #1139
  • allow matching hooks to multiple actions with "|" #1149
  • fix serializers datetime flaky test #1151

New Contributors

Full Changelog: https://github.com/moleculerjs/moleculer/compare/v0.14.25...v0.14.26

moleculer - v0.14.25

Published by icebob almost 2 years ago

Changes

  • fix Node 19 compatibility

Full Changelog: https://github.com/moleculerjs/moleculer/compare/v0.14.24...v0.14.25

moleculer - v0.14.24

Published by icebob about 2 years ago

Changes

  • allow moleculer-runner to resolve configuration files from node_modules #1126
  • fixed slower broker startup time issue #1132
  • fixed memory leak at dynamic service creation #1121
  • fixed invalid 'undefined' type in validator schema. #1137
  • update dependencies
moleculer - v0.14.23

Published by icebob about 2 years ago

Changes

  • fixed timeout issue in waitForServices method #1123
  • fixed metadata issue when compression enabled #1122
moleculer - v0.14.22

Published by icebob about 2 years ago

35 commits from 11 contributors.

Changes

  • fixed 'Ctx is undefined when using shard strategy and preferLocal is false, throws error on emit' #1072
  • fixed info packet send at broker stop #1101
  • added support for either-or versions to waitForServices #1030
  • fixed streaming issue with compression #1100
  • add requestID to debug logs in transit #1104
  • removed static on methods for the use of ServiceFactory #1098
  • fixed the issue with setting tracing and metrics options with env variables #1112
  • added dependencyTimeout broker option #1118
  • improved d.ts #1099 #1111 #1115
  • updated dependencies
moleculer - v0.14.21

Published by icebob over 2 years ago

20 commits from 2 contributors.

ESM support #1063

This version contains an ESM-based Moleculer Runner. This Runner is able to load ESM configuration file and ESM services. It can load the CJS services, as well

Example usage

moleculer-runner-esm --repl services/**/*.service.mjs

Moreover, the index.js file is wrapped into index.mjs, so you can import internal modules from the core in ESM modules. E.g.:

import { ServiceBroker, Errors } from "moleculer";

Please note, the hot-reload function doesn't work with this ESM Runner. The cause: https://github.com/nodejs/modules/issues/307
Node maintainers try to solve the missing features (module cache and module dependency tree) with loaders but this API is not stable yet.

Other Changes

  • broker.stopping property is created to indicate that broker is in stopping state.
moleculer - v0.14.20

Published by icebob over 2 years ago

52 commits from 8 contributors.

Dependency logic changed #1077

In mixed architecture, it's not hard to create a circular service dependency that may cause a dead-lock during the start of Moleculer nodes. The problem is that Moleculer node only sends the local service registry to remote nodes after all local services started properly.
As of 0.14.20, this behavior has changed. The new logic uses a debounced registry sending method which is triggered every time a local service, that the node manages, has started().
Note that the new method generates more INFO packets, than early versions, during the start of the node. The number of INFO packets depends on the number of the services that the node manages. The debounce timeout, between sending INFO packets, is 1 second.

Other Changes

  • fix ActionLogger and TransitLogger middlewares.
  • update Datadog Logger using v2 API. #1056
  • update dependencies.
  • update d.ts file. #1064, #1073
  • fix pino child logger bindings. #1075
moleculer - v0.14.19

Published by icebob almost 3 years ago

69 commits from 7 contributors.

Custom error recreation feature #1017

You can create a custom Regenerator class which is able to serialize and deserialize your custom errors. It's necessary when the custom error is created on a remote node and must be serialized to be able to sent back to the caller.

Create a custom Regenerator

const { Regenerator, MoleculerError } = require("moleculer").Errors;

class TimestampedError extends MoleculerError {
    constructor(message, code, type, data, timestamp) {
        super(message, code, type, data);
        this.timestamp = timestamp;
    }
}

class CustomRegenerator extends Regenerator {
    restoreCustomError(plainError, payload) {
        const { name, message, code, type, data, timestamp } = plainError;
        switch (name) {
            case "TimestampedError":
                return new TimestampedError(message, code, type, data, timestamp);
        }
    }
    extractPlainError(err) {
        return {
            ...super.extractPlainError(err),
            timestamp: err.timestamp
        };
    }
}
module.exports = CustomRegenerator;

Use it in broker options

// moleculer.config.js
const CustomRegenerator = require("./custom-regenerator");
module.exports = {
    errorRegenerator: new CustomRegenerator()
}

Error events #1048

When an error occured inside ServiceBroker, it's printed to the console, but there was no option that you can process it programatically (e.g. transfer to an external monitoring service). This feature solves it. Every error inside ServiceBroker broadcasts a local (not transported) event ($transporter.error, $broker.error, $transit.error, $cacher.error, $discoverer.error) what you can listen in your dedicated service or in a middleware.

Example to listen in an error-tracker service

module.exports = {
    name: "error-tracker",

    events: {
        "$**.error": {
            handler(ctx) {
                // Send the error to the tracker
                this.sendError(ctx.params.error);
            }
        }
    }
}

Example to listen in a middleware or in broker options

module.exports = {
    created(broker) {
        broker.localBus.on("*.error", payload => {
            // Send the error to the tracker
            this.sendError(payload.error);
        });
    }
}

Wildcards in Action Hooks #1051

You can use * wildcard in action names when you use it in Action Hooks.

Example

hooks: {
    before: {
        // Applies to all actions that start with "create-"
        "create-*": [],
        
        // Applies to all actions that end with "-user"
        "*-user": [],
    }
}

Other Changes

  • update dependencies.
  • update d.ts file. #1025, #1028, #1032
  • add safetyTags option to tracing exporters. #1052
moleculer - v0.14.18

Published by icebob about 3 years ago

20 commits from 7 contributors.

Changes

  • update dependencies.
  • expose Cacher and Validator middlewares. #1012
  • update d.ts file. #1013
  • parse user & password from NATS server urls. #1021
moleculer - v0.14.17

Published by icebob about 3 years ago

61 commits from 10 contributors.

Changes

  • reformat codebase with Prettier.
  • fix binding issue in Pino logger. #974
  • update d.ts file. #980 #970
  • transit message handler promises are resolved. #984
  • fix cacher issue if cacher is not connected. #987
  • fix Jest open handlers issue. #989
  • fix cacher cloning issue. #990
  • add custom headers option to Zipkin trace exporter. #993
  • fix heartbeatTimeout option in BaseDiscoverer. #985
  • add cacher keygen option action definition. #1004
  • update dependencies
moleculer - v0.14.16

Published by icebob over 3 years ago

11 commits from 4 contributors.

Changes

  • fix nats-streaming version in peerDependencies.
  • RedisCacher pingInterval option. #961
  • Update NATS transporter messages to debug. #963
  • update d.ts file. #964 #966
  • update dependencies
moleculer - v0.14.15

Published by icebob over 3 years ago

15 commits from 5 contributors.

Changes

  • fix nats version in peerDependencies.
  • convert url to servers in nats@2. #954
  • add typing for mcall settled option. #957
  • revert TS ThisType issue in 0.14.14. #958
  • update dependencies
  • add useTag259ForMaps: false default option for CBOR serializer to keep the compatibility.
moleculer - v0.14.14

Published by icebob over 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 in broker.mcall

The broker.mcall method has a new settled 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 rejected Promise and you don't know how many (and which) calls were rejected.

If settled: true, the method returns a resolved Promise 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 the nats 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, the FastestValidator passes the ctx 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