@kos-ng-it-konsult/rabbit
v0.0.4
Published
RabbitMQ package for KOS-NG IT Konsult
Readme
@kos-ng-it-konsult/rabbit
This is a rabbit-mq wrapper package for KOS NG IT Konsult.
Quick Start
Install
$ npm i --save @kos-ng-it-konsult/rabbit
Basic Usage
const rabbit = require('@kos-ng-it-konsult/rabbit');
const exchange = 'sample_exchange';
const logger = console;
// create a new instance
const new_rabbit = new rabbit(logger, exchange);
// connect to an amqp server
await new_rabbit.connect('amqp://localhost');
// add a consume channel
await new_rabbit.addChannel('CONSUME');
// add consumer queues
await new_rabbit.createConsumeChannelQueue([ ...Queues ]);
// add a publish channel
await new_rabbit.addChannel('PUBLISH');
// get exchange name
console.log(new_rabbit.getExchangeName()); // Outputs sample_exchange
// publish a message to a queue
await new_rabbit.publish(exchange, 'tes_cre_use', { ... }, true);
// close consume channel
await new_rabbit.closeChannel('CONSUME');
// close publish channel
await new_rabbit.closeChannel('PUBLISH');
// close connection
await new_rabbit.closeConnection();Running the Example
To run the example, simply run the commands in separate command windows:$ npm run consume$ npm run publish
Running Tests
Run$ npm test
