Skip to content
Hooked Continuation-Local Storage for Moleculer
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.gitignore initial version. Feb 28, 2019
CHANGELOG.md initial version. Feb 28, 2019
README.md update readme Feb 28, 2019
index.js initial version. Feb 28, 2019
package-lock.json initial version. Feb 28, 2019
package.json initial version. Feb 28, 2019

README.md

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: {
        "name": "string"
      },
      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

You can’t perform that action at this time.