@johnmmackey/amqp-persistent
v2.0.3
Published
Class for persistent AMQP connections
Readme
amqp-msrvlib
Wrapper for ampqlib providing persistent connection to the AMQP server.
Due to the use of ES6 features, this module requires Node.js V8 or above.
Quickstart
npm install @johnmmackey/amqp-persistentconst { amqpPersistentConnection } = require('@johnmmackey/amqp-persistent');
// Establish a connection to server
// Server URI is taken from AMQP_URI environment variable.
// If not set, defaults to 'amqp://localhost'
amqpPersistentConnection.connect();
// Alternately, a server can be specified:
amqpPersistentConnection.connect('amqp://amqpserver.domain.com');amqpPersistentConnection is an instance of EventEmitter. Events:
debug: informationalready: when connection is readyfailed: if connection drops
Usage example:
amqpPersistentConnection.on('debug', status => {
console.log('AMPQ Connection debug:', status);
});Core Methods
A connection has the following core methods:
- addConfig(f), where f is a function returning a promise. Example:
amqpPersistentConnection.addConfig(async ch => {
await ch.assertExchange('sillyex', 'fanout');
await ch.assertQueue('sillyq');
await ch.bindQueue('sillyq', 'sillyex', '');
ch.consume('sillyq', msg => {
myConsumerFunction(msg);
}, { noAck: true });
});- amqpPersistentConnection.ack(msg) - acknowledge a message (used in consumer functions)
