Skip to content

akil-io/queue

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

RabbitMQ wrapper for PubSub, RPC, Queue based on official examples for amqplib

Init

const RabbitMQ = require('env-rmq').RabbitMQ;

const rmq = new RabbitMQ({
	uri: 'amqp://user:password@localhost/'
});
rmq.connect().then(() => {
	console.log('Ready.');
}).catch(err => {
	console.log('Error: ', err);
});

Queue

Worker - handle task

rmq.worker('my-queue-name', function (msg, reject, ack) {
	ack();
});

Client - send task

// Assert channel on application loading
rmq.worker('my-queue-name');

// Send task everywhere
rmq.worker('my-queue-name').send({
	someField: "Hello world!"
});

PubSub

Listener

rmq.pubsub('my-pub-name', function (msg, reject, ack) {
	ack();
});

Sender

// Assert channel on application loading
rmq.pubsub('my-pub-name');

rmq.pubsub('my-pub-name').send({
	someField: "Hello world!"
});

RPC

Server

rmq.rpc('my-function', function (msg, reject, ack) {
	ack({
		returnValue:"OK!"
	});
});

Client

// Assert channel on application loading
rmq.rpc('my-function');

rmq.rpc('my-function').call({
	someField: "Hello world!"
}).then(result => {
	console.log("RETURNED VALUE:", result);
});

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published