Nondigestible Purple Mayonnaise

    moleculer-cls

    1.1.0 • Public • Published

    Hooked Continuation-Local Storage for Moleculer

    Add support for continuation local storage in moleculer action handlers.

    Current Version (v1.0.0)

    Install

    npm install --save moleculer-cls

    Usage

    // moleculer.config.js
    
    const context = require('moleculer-cls');
    
    module.exports = {
      ...
      middlewares: [
        context.middleware
      ]
    }
    // service.js
    
    const context = require('moleculer-cls');
    const process = require('processor.js');
    
    module.exports = {
      actions: {
        hello: {
          params: {
            properties: {
              "name": {type: "string"}
            },
            required: ["name"]
          },
          handler: async (ctx) => {
            context.set('request_id', ctx.requestID);
            
            return await process(ctx.params);
          }
        }
      }
    }
    // processor.js
    
    const context = require('moleculer-cls');
    
    module.exports = async ({name}) => {
      console.log(`Processing ${context.get('request_id')}`);
    
      return Promise.resolve(`Hello ${name}`);
    }

    License

    MIT

    Install

    npm i moleculer-cls

    DownloadsWeekly Downloads

    8

    Version

    1.1.0

    License

    MIT

    Unpacked Size

    2.67 kB

    Total Files

    4

    Last publish

    Collaborators

    • avatar