Skip to content

lehno/moleculer-amqp-queue

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Moleculer logo

moleculer-amqp-queue NPM version

Task queue mixin for AMQP.

Install

$ npm install moleculer-amqp-queue --save

Usage

Create queue worker service

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

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.

Contact

Copyright (c) 2016-2018 MoleculerJS

@moleculerjs @MoleculerJS

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •