Larvitamintercom
Communication wrapper for rabbitmq in autobahn.
Usage
Connection
When instantiating a new intercom it will try to connect instantly and on connection error or connection lost it will try to reconnect an infinite number of times every 1sec.
Send
send() to autobahn.
const Intercom = require('larvitamintercom'),
conStr = 'amqp://user:password@192.168.0.1/',
intercom = new Intercom(conStr);
let message = {'hello': 'world'},
options = {'exchange': 'foo'};
intercom.send(message, options, function (err, msgUuid) {
});
Default send options:
{
'exchange': 'default',
'durable': true,
'forceConsumeQueue': false
}
Read
There are two types of read operations; "consume" and "subscribe".
A message can only be "consumed" once, but it can be "subscribed" several times, by different readers.
Consumers can be assigned to an exchanged after the message have been sent, and they still receive the message.
However, very importantly, ONE consumer must be assigned before the send happends, or the consumer queue never gets declared!
Subscribers, in contrast, must subscribe BEFORE the message is sent or they will not receive it.
Each subscriber only get each message once.
Consume
const Intercom = require('larvitamintercom'),
conStr = 'amqp://user:password@192.168.0.1/',
intercom = new Intercom(conStr);
let options = {'exchange': 'foo'};
intercom.consume(options, function (message, ack, deliveryTag) {
ack();
ack(new Error('Something was wrong with the message'));
}, function (err) {
});
Default consume options:
{
'exchange': 'default'
}
Subscribe
const Intercom = require('larvitamintercom').Intercom,
conStr = 'amqp://user:password@192.168.0.1/',
intercom = new Intercom(conStr);
let options = {'exchange': 'default'};
intercom.subscribe(options, function (message, ack, deliveryTag) {
ack();
ack(new Error('Something was wrong with the message'));
}, function (err, subscribeInstance) {
});
Default subscribe options:
{
'exchange': 'default'
}
Custom logging
const Intercom = require('larvitamintercom').Intercom,
winston = require('winston'),
log = winston.createLogger({'transports': [new winston.transports.Console()]}),
conStr = 'amqp://user:password@192.168.0.1/',
intercom = new Intercom({'conStr': conStr, 'log': log});