https://github.com/lehno/moleculer-amqp-queue
https://github.com/lehno/moleculer-amqp-queue
Last synced: 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/lehno/moleculer-amqp-queue
- Owner: lehno
- License: mit
- Created: 2019-06-28T09:46:58.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2023-01-04T01:26:31.000Z (over 2 years ago)
- Last Synced: 2024-08-03T02:06:10.257Z (11 months ago)
- Language: JavaScript
- Size: 1.02 MB
- Stars: 2
- Watchers: 0
- Forks: 10
- Open Issues: 12
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
- awesome-moleculer - moleculer-amqp-queue - Task queue mixin for [AMQP](https://www.amqp.org/) (Mixins / Tasks, Queues and Jobs)
README

# moleculer-amqp-queue [](https://www.npmjs.com/package/moleculer-amqp-queue)
Task queue mixin for [AMQP](https://www.amqp.org/).
# Install
```bash
$ npm install moleculer-amqp-queue --save
```# Usage
## Create queue worker service
```js
const AMQPMixin = require("moleculer-amqp-queue");broker.createService({
name: "task-worker",
mixins: [AMQPMixin],
AMQPQueues: {
"sample.task": {
handler (channel, msg) {
let job = JSON.parse(msg.content.toString());
this.logger.info("New job received!", job.id);
setTimeout(() => {
channel.ack(msg);
}, 500);
},
channel: {
assert: {
durable: true,
},
prefetch: 1,
},
consume: {
noAck: false,
},
}
}
});
```## Create job in service
```js
const QueueService = require("moleculer-amqp-queue");broker.createService({
name: "job-maker",
mixins: [QueueService],
methods: {
sampleTask(data) {
const jobOption = {
persistent: false,
};
const job = this.addAMQPJob("sample.task", data);
}
}
});
```# Test
```
$ npm test
```In development with watching
```
$ npm run ci
```# License
The project is available under the [MIT license](https://tldrlegal.com/license/mit-license).# Contact
Copyright (c) 2016-2018 MoleculerJS[](https://github.com/moleculerjs) [](https://twitter.com/MoleculerJS)