jackrabbitjs
v1.3.1
Published
[![npm version](https://badge.fury.io/js/jackrabbitjs.svg)](https://badge.fury.io/js/jackrabbitjs) [![Build Status](https://travis-ci.org/acmadden/jackrabbitjs.svg?branch=master)](https://travis-ci.org/acmadden/jackrabbitjs)
Downloads
9
Readme
JackrabbitJS
JackrabbitJS is a amqplib
wrapper built to hide the complexities of messaging protocols. It was built for smaller to midlevel projects that need a simple messaging api that works.
Usage
Installing JackrabbitJS
npm install jackrabbitjs --save
Consumer:
const jackrabbit = require('jackrabbitjs');
const credentials = {
uri: 'server-uri',
user: 'jack',
password: 'rabbitjs'
};
let options = {
queue: 't',
ack: true
};
jackrabbit.connect(credentials, (err, connection) => {
jackrabbit.consume(connection, options, (err, message) => {
console.log(message.content.toString());
});
});
Producer:
const jackrabbit = require('jackrabbitjs');
const credentials = {
uri: 'server-uri',
user: 'jack',
password: 'rabbitjs'
};
let options = {
queue: 't',
payload: 'ello',
timeout: 3000
};
jackrabbit.connect(credentials, (err, connection) => {
if (err) {
process.exit(1);
}
jackrabbit.produce(connection, options);
});
RPC-Consumer:
const jackrabbit = require('jackrabbitjs');
const credentials = {
uri: 'server-uri',
user: 'jack',
password: 'rabbitjs'
};
let options = {
queue: 't',
rpc: true
};
jackrabbit.connect(credentials, (err, connection) => {
jackrabbit.consume(connection, options, (e, message, channel) => {
if(channel) {
jackrabbit.reply(message.properties.replyTo, message.properties.correlationId, channel, 'jackrabbitjs');
}
});
});
RPC-Producer:
const jackrabbit = require('jackrabbitjs');
const credentials = {
uri: 'server-uri',
user: 'jack',
password: 'rabbitjs'
};
let options = {
queue: 't',
payload: 'ello',
rpc: true,
exclusive: true,
timeout: 3000
};
jackrabbit.connect(credentials, (err, connection) => {
jackrabbit.produce(connection, options, (err, reply) => {
// do stuff with the message
});
});
Options:
uri: [the RabbitMQ server uri]
user: If the user is specified in the uri, this is not needed.
password: If the password is specified in the uri, this is not needed.
payload: [the payload sent to the consumer]
function: [function call sent to the consumer]
exclusive: defaults to false,
rpc: defaults to false,
ack: defaults to true,
persistent: defaults to false,
durable: defaults to false,
prefetch: defaults to 1,
timeout: defaults to -1. The connection must be closed manually if a timeout is not specified.
Roadmap
version 1.1
- [x] basic one way publish
- [x] basic one way consume
version 1.2
- [x] consume with acknowledgement and reply
- [x] publish receives acknowledgement and reply
version 1.3
- [x] refactor to simplify api
version 1.4
- [ ] broadcast to multiple consumers
miscellaneous
- [ ] documentation