moleculer-rabbit-amqp
v1.0.0
Published
Task queue service with AMQP
Downloads
6
Readme
moleculer-rabbit-amqp
Task queue mixin for AMQP.
Install
$ npm install moleculer-rabbit-amqp --save
Usage
Use settings to set the configurations
settings = {
url: "amqp://localhost",
}
Create queue worker service
const AMQPMixin = require("moleculer-rabbit-amqp");
const configs = {
//If you have bind queue configuration
retryQueue: null,
retryExchange: null,
retryRoutingKey: null,
deadLetterOptions: {
durable: true,
arguments: { //here you can set x-dead-letter to retry queue, TTL, x-queue-type, etc. Example: "x-dead-letter-retry-exchange": "exchange_retry_queue"
},
},
queueOptions: {
durable: true,
arguments: {
//here you can set x-dead-letter to queue, x-queue-type, etc. Example: "x-dead-letter-exchange": "exchange_queue"
},
}
}
broker.createService({
name: "task-worker",
mixins: [AMQPMixin()],
settings: { }
AMQPQueues: [{
"queue_name" (channel, msg) {
let job = JSON.parse(msg.content.toString());
this.logger.info("New job received!", job.id);
setTimeout(() => {
channel.ack(msg);
}, 500);
}
}, configs]
});
Create job in service
const QueueService = require("moleculer-rabbit-amqp");
const configs = {
//If you have bind queue configuration
retryQueue: null,
retryExchange: null,
retryRoutingKey: null,
deadLetterOptions: {
durable: true,
arguments: { //here you can set x-dead-letter to retry queue, TTL, x-queue-type, etc. Example: "x-dead-letter-retry-exchange": "exchange_retry_queue"
},
},
queueOptions: {
durable: true,
arguments: {
//here you can set x-dead-letter to queue, x-queue-type, etc. Example: "x-dead-letter-exchange": "exchange_queue"
},
}
}
broker.createService({
name: "job-maker",
mixins: [QueueService()],
settings: {}
methods: {
sampleTask(data) {
const job = this.addAMQPJob("queue_name", data, configs);
}
}
});
Test
$ npm test
In development with watching
$ npm run ci
License
The project is available under the MIT license.
Contact
Copyright (c) 2016-2018 MoleculerJS