Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/cupsadarius/moleculer-cls
Hooked Continuation-Local Storage for Moleculer
https://github.com/cupsadarius/moleculer-cls
continuation-local-storage microservices middleware moleculer
Last synced: 3 months ago
JSON representation
Hooked Continuation-Local Storage for Moleculer
- Host: GitHub
- URL: https://github.com/cupsadarius/moleculer-cls
- Owner: cupsadarius
- Created: 2019-02-28T19:54:44.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2024-04-05T08:59:31.000Z (7 months ago)
- Last Synced: 2024-07-08T11:12:36.714Z (4 months ago)
- Topics: continuation-local-storage, microservices, middleware, moleculer
- Language: JavaScript
- Size: 33.2 KB
- Stars: 4
- Watchers: 1
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
- awesome-moleculer - moleculer-cls - Hooked Continuation-Local Storage for Moleculer (Services / Others)
README
# Async Local Storage for Moleculer
Add support for async local storage in moleculer action handlers.
## Current Version (v2.1.0)
- support [moleculer ^0.14.x](https://github.com/moleculerjs/moleculer)
- accept nodejs: >=18## Install
`npm install --save moleculer-cls`
## Usage
```js
// moleculer.config.jsconst context = require('moleculer-cls');
module.exports = {
...
middlewares: [
context.middleware
]
}
``````js
// service.jsconst 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);
}
}
}
}
``````js
// processor.jsconst context = require('moleculer-cls');
module.exports = async ({name}) => {
console.log(`Processing ${context.get('request_id')}`);return Promise.resolve(`Hello ${name}`);
}
```## License
MIT