All Versions
58
Latest Version
Avg Release Cycle
32 days
Latest Release
67 days ago

Changelog History
Page 1

  • v0.14.11

    September 27, 2020

    ๐Ÿ†• New merged service lifecycle hook

    ๐Ÿ”€ Service has a new merged lifecycle hook which is called after the service schemas (including mixins) has been merged but before service is registered. It means you can manipulate the merged service schema before it's processed.

    Example

    // posts.service.js
    module.exports = {
        name: "posts",
    
        settings: {},
    
        actions: {
            find: {
                params: {
                    limit: "number"
                }
                handler(ctx) {
                    // ...
                }
            }
        },
    
        merged(schema) {
            // Modify the service settings
            schema.settings.myProp = "myValue";
            // Modify the param validation schema in an action schema
            schema.actions.find.params.offset = "number";
        }
    };
    

    Other changes

    • โž• add requestID tag to all action and event spans #802
    • ๐Ÿ›  fix bug in second level of mixins with $secureSettings #811

  • v0.14.10

    August 23, 2020

    ๐Ÿ”„ Changes

    • โšก๏ธ update dependencies
    • ๐Ÿ›  fix issues in index.d.ts
    • ๐Ÿ›  fix broadcast event sending issue when disableBalancer: true #799 (thanks for ngraef)

  • v0.14.9

    August 06, 2020

    Register method in module resolver

    If you create a custom module (e.g. serializer), you can register it into the built-in modules with the register method. This method is also available in all other built-in module resolver.

    Example

    // SafeJsonSerializer.js
    const { Serializers } = require("moleculer");
    
    class SafeJsonSerializer {}
    
    Serializers.register("SafeJSON", SafeJSON);
    
    module.exports = SafeJsonSerializer;
    
    // moleculer.config.js
    require("./SafeJsonSerializer");
    
    module.exports = {
        nodeID: "node-100",
        serializer: "SafeJSON"
        // ...
    });
    

    ๐Ÿ”„ Changeable validation property name

    You can change the params property name in validator options. It can be useful if you have a custom Validator implementation.

    const broker = new ServiceBroker({
        validator: {
            type: "Fastest",
            options: {
                paramName: "myParams" // using `myParams` instead of `params`
            }
        }
    });
    
    broker.createService({
        name: "posts",
        actions: {
            create: {
                myParams: {
                    title: "string"
                }
            },
            handler(ctx) { /* ... */ }
        }
    });
    

    Global tracing span tags for actions & events

    ๐Ÿ”ง Thanks for @kthompson23, you can configure the action & events tracing span tags globally. These tags will be used for all actions & events where tracing is enabled. Of course, you can overwrite them locally in the action & event schema.

    Example

    // moleculer.config.js
    module.exports = {
        tracing: {
            enabled: true,
            exporter: 'Zipkin',
            tags: {
                action: {
                    meta: ['app.id', 'user.email', 'workspace.name'],
                    params: false,  // overrides default behavior of all params being adding as tags
                    response: true,
                },
                event: (ctx) {
                    return {
                        caller: ctx.caller,
                    }
                }  
            }
        }
    }
    

    Other changes

    • ๐Ÿ›  fix multiple trace spans with same ID issue in case of retries.
    • โšก๏ธ update dependencies
    • โž• add lastValue property to histogram metric type.
    • โšก๏ธ update return type of context's copy method.
    • โž• add configuration hotReloadModules #779
    • โœ‚ Remove Zipkin v1 annotations and change kind to SERVER

  • v0.14.8

    June 27, 2020

    Github Sponsoring is available for Moleculer :tada:

    We have been approved in Github Sponsors program, so you can sponsor the Moleculer project via Github Sponsors. If you have taxing problem with Patreon, change to Github Sponsors.

    ๐Ÿ†• New Validator configuration

    ๐Ÿ”ง The validator has the same module configuration in broker options like other modules. It means you can configure the validation constructor options via broker options (moleculer.config.js).

    0๏ธโƒฃ Default usage:

    //moleculer.config.js
    module.exports = {
        nodeID: "node-100",
        validator: true // Using the default Fastest Validator
    }
    

    Using built-in validator name:

    //moleculer.config.js
    module.exports = {
        nodeID: "node-100",
        validator: "FastestValidator" // Using the Fastest Validator
    }
    

    Example with options:

    //moleculer.config.js
    module.exports = {
        nodeID: "node-100",
        validator: {
            type: "FastestValidator",
            options: {
                useNewCustomCheckerFunction: true,
                defaults: { /*...*/ },
                messages: { /*...*/ },
                aliases: { /*...*/ }
            }
        }
    }
    

    Example with custom validator

    //moleculer.config.js
    const BaseValidator = require("moleculer").Validators.Base;
    
    class MyValidator extends BaseValidator {}
    
    module.exports = {
        nodeID: "node-100",
        validator: new MyValidator()
    }
    

    ๐Ÿ†• New metrics

    โž• Added the following new metrics:

    • moleculer.event.received.active: Number of active event executions.
    • moleculer.event.received.error.total: Number of event execution errors.
    • moleculer.event.received.time: Execution time of events in milliseconds.
    • os.memory.total: OS used memory size.

    Other changes

    • ๐Ÿ‘Œ support using moleculer.config.js with export default.
    • โœ‚ remove some lodash methods.
    • โฌ†๏ธ upgrade to the latest tsd.
    • ๐Ÿ†• new dependencyInterval broker option. Using as default value for broker.waitForServices #761
    • ๐Ÿ›  fix Datadog traceID, spanID generation logic to work with latest dd-trace.
    • โž• add error stack trace to EventLegacy trace exporter.
    • ๐Ÿ›  fix INFO key issue in Redis Discoverer after Redis server restarting.

  • v0.14.7

    May 22, 2020

    ๐Ÿ†• New Discoverer module

    ๐Ÿšš The Discoverer is a new built-in module in Moleculer framework. It's responsible for that all Moleculer nodes can discover each other and check them with heartbeats. In previous versions, it was an integrated module inside ServiceRegistry & Transit modules. In this version, the discovery logic has been extracted to a separated built-in module. It means you can replace it to other built-in implementations or a custom one. The current discovery & heartbeat logic is moved to the Local Discoverer.

    Nevertheless, this version also contains other discoverers, like Redis & etcd3 discoverers. Both of them require an external server to make them work. One of the main advantages of the external discoverers, the node discovery & heartbeat packets don't overload the communication on the transporter. The transporter transfers only the request, response, event packets. By the way, the external discoverers have some disadvantages, as well. These discoverers can detect lazier the new and disconnected nodes because they scan the heartbeat keys periodically on the remote Redis/etcd3 server. The period of checks depends on the heartbeatInterval broker option.

    0๏ธโƒฃ >The Local Discoverer (which is the default) works like the discovery of previous versions, so if you want to keep the original logic, you'll have to do nothing.

    Please note the TCP transporter uses Gossip protocol & UDP packets for discovery & heartbeats, it means it can work only with Local Discoverer.

    Local Discoverer

    ๐ŸŽ It's the default Discoverer, it uses the transporter module to discover all other moleculer nodes. It's quick and fast but if you have too many nodes (>100), the nodes can generate a lot of heartbeat packets which can reduce the performance of request/response packets.

    Example

    // moleculer.config.js
    module.exports = {
        registry: {
            discoverer: "Local"
        }    
    }
    

    Example with options

    // moleculer.config.js
    module.exports = {
        registry: {
            discoverer: {
                type: "Local",
                options: {
                    // Send heartbeat in every 10 seconds
                    heartbeatInterval: 10,
    
                    // Heartbeat timeout in seconds
                    heartbeatTimeout: 30,
    
                    // Disable heartbeat checking & sending, if true
                    disableHeartbeatChecks: false,
    
                    // Disable removing offline nodes from registry, if true
                    disableOfflineNodeRemoving: false,
    
                    // Remove offline nodes after 10 minutes
                    cleanOfflineNodesTimeout: 10 * 60
                }
            }
        }    
    }
    

    Redis Discoverer

    This is an experimental module. Do not use it in production yet!

    ๐Ÿšš This Discoverer uses a Redis server to discover Moleculer nodes. The heartbeat & discovery packets are stored in Redis keys. Thanks to Redis key expiration, if a node crashed or disconnected unexpectedly, the Redis will remove its heartbeat keys from the server and other nodes can detect it.

    Example to connect local Redis server

    // moleculer.config.js
    module.exports = {
        registry: {
            discoverer: "Redis"
        }    
    }
    

    Example to connect remote Redis server

    // moleculer.config.js
    module.exports = {
        registry: {
            discoverer: "redis://redis-server:6379"
        }    
    }
    

    Example with options

    // moleculer.config.js
    module.exports = {
        registry: {
            discoverer: {
                type: "Redis",
                options: {
                    redis: {
                        // Redis connection options.
                        // More info: https://github.com/luin/ioredis#connect-to-redis
                        port: 6379,
                        host: "redis-server",
                        password: "123456",
                        db: 3
                    }
    
                    // Serializer
                    serializer: "JSON",
    
                    // Full heartbeat checks. It generates more network traffic
                    // 10 means every 10 cycle.
                    fullCheck: 10,
    
                    // Key scanning size
                    scanLength: 100,
    
                    // Monitoring Redis commands
                    monitor: true,
    
                    // --- COMMON DISCOVERER OPTIONS ---
    
                    // Send heartbeat in every 10 seconds
                    heartbeatInterval: 10,
    
                    // Heartbeat timeout in seconds
                    heartbeatTimeout: 30,
    
                    // Disable heartbeat checking & sending, if true
                    disableHeartbeatChecks: false,
    
                    // Disable removing offline nodes from registry, if true
                    disableOfflineNodeRemoving: false,
    
                    // Remove offline nodes after 10 minutes
                    cleanOfflineNodesTimeout: 10 * 60
                }
            }
        }    
    }
    

    To be able to use this Discoverer, install the ioredis module with the npm install ioredis --save command.

    Tip: To further network traffic reduction, you can use MsgPack/Notepack serializers instead of JSON.

    Etcd3 Discoverer

    This is an experimental module. Do not use it in production yet!

    ๐Ÿšš This Discoverer uses an etcd3 server to discover Moleculer nodes. The heartbeat & discovery packets are stored in the server. Thanks to etcd3 lease solution, if a node crashed or disconnected unexpectedly, the etcd3 will remove its heartbeat keys from the server and other nodes can detect it.

    Example to connect local etcd3 server

    // moleculer.config.js
    module.exports = {
        registry: {
            discoverer: "Etcd3"
        }    
    }
    

    Example to connect remote etcd3 server

    // moleculer.config.js
    module.exports = {
        registry: {
            discoverer: "etcd3://etcd-server:2379"
        }    
    }
    

    Example with options

    // moleculer.config.js
    module.exports = {
        registry: {
            discoverer: {
                type: "Etcd3",
                options: {
                    etcd: {
                        // etcd3 connection options.
                        // More info: https://mixer.github.io/etcd3/interfaces/options_.ioptions.html
                        hosts: "etcd-server:2379",
                        auth: "12345678"
                    }
    
                    // Serializer
                    serializer: "JSON",
    
                    // Full heartbeat checks. It generates more network traffic
                    // 10 means every 10 cycle.
                    fullCheck: 10,
    
                    // --- COMMON DISCOVERER OPTIONS ---
    
                    // Send heartbeat in every 10 seconds
                    heartbeatInterval: 10,
    
                    // Heartbeat timeout in seconds
                    heartbeatTimeout: 30,
    
                    // Disable heartbeat checking & sending, if true
                    disableHeartbeatChecks: false,
    
                    // Disable removing offline nodes from registry, if true
                    disableOfflineNodeRemoving: false,
    
                    // Remove offline nodes after 10 minutes
                    cleanOfflineNodesTimeout: 10 * 60
                }
            }
        }    
    }
    

    To be able to use this Discoverer, install the etcd3 module with the npm install etcd3--save command.

    Tip: To further network traffic reduction, you can use MsgPack/Notepack serializers instead of JSON.

    Custom Discoverer

    You can create your custom Discoverer. We recommend to copy the source of Redis Discoverer and implement the necessary methods.

    Other changes

    • ๐Ÿ›  fixed multiple heartbeat sending issue at transporter reconnecting.
    • 0๏ธโƒฃ the heartbeatInterval default value has been changed to 10 seconds.
    • 0๏ธโƒฃ the heartbeatTimeout default value has been changed to 30 seconds.
    • ๐Ÿ”€ the heartbeat check logics use process uptime instead of timestamps in order to avoid issues with time synchronization or daylight saving.
    • ๐Ÿ›  Notepack serializer initialization issue fixed. It caused problem when Redis cacher uses Notepack serializer.
    • ๐Ÿ†• new removeFromArray function in Utils.
    • ๐Ÿ›  mcall method definition fixed in Typescript definition.
    • โšก๏ธ dependencies updated.

  • v0.14.6

    April 11, 2020

    ๐Ÿ†• New NewRelic zipkin tracing exporter

    Thanks for @jalerg, there is a NewRelic tracing exporter. PR #713

    // moleculer.config.js
    {
        tracing: {
            enabled: true,
            events: true,
            exporter: [
                {
                    type: 'NewRelic',
                    options: {
                        // NewRelic Insert Key
                        insertKey: process.env.NEW_RELIC_INSERT_KEY,
                        // Sending time interval in seconds.
                        interval: 5,
                        // Additional payload options.
                        payloadOptions: {
                            // Set `debug` property in payload.
                            debug: false,
                            // Set `shared` property in payload.
                            shared: false,
                        },
                        // Default tags. They will be added into all span tags.
                        defaultTags: null,
                    },
                },
            ],
        },    
    }
    

    Other changes

    • ๐Ÿ›  fix stream chunking issue. PR #712
    • ๐Ÿ›  fix INFO packet sending issue after reconnecting
    • safely handling disconnected state for transporters (heartbeat queuing issue). PR #715
    • ๐Ÿ›  fix orhpan response issue in case of streaming with disabled balancer. #709
    • โšก๏ธ update dependencies, audit fix

  • v0.14.5

    March 25, 2020

    Wrapping service methods with middlewares

    ๐Ÿ†• New localMethod hook in middlewares which wraps the service methods.

    Example

    // my.middleware.js
    module.exports = {
        name: "MyMiddleware",
    
        localMethod(next, method) {
            return (...args) => {
                console.log(`The '${method.name}' method is called in '${method.service.fullName}' service.`, args);
                return handler(...args);
            }
        }
    }
    

    Schema for service methods

    Similar for action schema, you can define service methods with schema. It can be useful when middleware wraps service methods.

    Example for new method schema

    // posts.service.js
    module.exports = {
        name: "posts",
    
        methods: {
            list: {
                async handler(count) {
                    // Do something
                    return posts;
                }
            }
        }
    };
    

    ๐Ÿ”„ Changes

    • โž• add chunk limit for streams in message transporting. #683
    • โž• add baseUrl option to Datadog metric reporter. #694
    • ๐Ÿ›  fix open handles in unit tests. #695
    • โšก๏ธ update d.ts #699 #700 #703

  • v0.14.4

    March 08, 2020

    ๐Ÿ”„ Changes

    • โž• add maxSafeObjectSize to service broker options. Fixes #697
    • โž• add stop method to tracing exporters. Fixes #689
    • ๐Ÿ›  fix EventLegacy tracing exporter. Fixes #676
    • 0๏ธโƒฃ the defaultTags property in tracer options can be a Function, as well.

  • v0.14.3

    February 24, 2020

    ๐Ÿ”„ Changes

    • ๐Ÿ›  fix issue in AMQP 1.0 transporter

  • v0.14.2

    February 14, 2020

    ๐Ÿ‘Œ Support custom loggers

    If you have your custom logger you should wrap it into a Logger class and implement the getLogHandler method.

    Using a custom logger

    // moleculer.config.js
     const BaseLogger = require("moleculer").Loggers.Base;
    
    class MyLogger extends BaseLogger {
        getLogHandler(bindings) {
            return (type, args) => console[type](`[MYLOG-${bindings.mod}]`, ...args);
        }
    }
    
    module.exports = {
        logger: new MyLogger()
    };