1.0.11 • Published 5 years ago
rabbitmq-amqp v1.0.11
Install
$ npm install rabbitmq-amqp
Usage
First of all, define Exchange, Queue and Binding between them in your RabbitMQ with 'durable' option in true. Then create an instance.
Examples
Create instance
//URL format: amqp://username:password@hostname-or-IP
const rabbit = new RabbitMQ(url)
Consume from queue
rabbit.consume('queue-name', callback , options) Options defaults: { noAck: true, priority: null } http://www.squaremobius.net/amqp.node/channel_api.html#channel_consume
rabbit.on('connected', () => {
rabbit.consume('queue-name', msg => {
console.log('New message received: ', msg)
})
})
Publish in exchange
rabbit.publish('exchange-name', message , options)) Options defaults: { topic: '', expirations: null, priority: null, persistent: false } http://www.squaremobius.net/amqp.node/channel_api.html#channel_publish
rabbit.publish('exchange-name', 'Hello world!')
Events
On connect
rabbit.on('connect', () => { console.log('Connected to RabbutMQ!') })
On disconnect
rabbit.on('disconnect', (reason) => { console.log(`Disconnected to RabbutMQ!. Reason: ${reason}`) })