Task queue mixin for AMQP.
$ npm install moleculer-amqp-queue --save
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,
},
}
}
});
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);
}
}
});
$ npm test
In development with watching
$ npm run ci
The project is available under the MIT license.
Copyright (c) 2016-2018 MoleculerJS