You will need an `exchangeName` for the channel and `bindings` to map keys to queues. ``` const MessageQueue = require('amqp-reuse');
npm install amqp-reuseYou will need an exchangeName for the channel and bindings to map keys to queues.
``
`
const MessageQueue = require('amqp-reuse');
const exchangeName = 'domfeed';
const bindings = {
enqueued: 'unverified_domains',
verified: 'verified_domains',
failed: 'failed_cf_lookups'
};
onChannelReady
Create a handler function for the parameter of the instance.
onChannelReady must be a function. Both connection and channel are returned and are the respective objects from AMQP.
publish
In this function, you can , consume, or otherwise utilize both the channel and connection.
flow
In this case, is the handler for the open AMQP connection and channel.
`
Consume Message ${i}: ${message.content.toString()}
const flow = ({ channel, connection }) => {
// we publish to exchanges
const publish = (message, key) => channel.publish(exchangeName, key, Buffer.from(message), { persistent: true })
// ... and we consume queues
var i = 0;
channel.consume('verified_domains', message => {
i++;
console.log();
`
setTimeout(() => channel.ack(message), Math.random() * 5000);
});
for (var i = 1000; i > 0; i--) {
setTimeout(() => {
publish('ping!', 'verified');
}, Math.random() * 60000);
}
}
MessageQueue
Create an instance of .
`
`
new MessageQueue({
exchangeName,
bindings,
onChannelReady: flow
});
onChannelReady.connection
Example parameters:
amqpUrl = 'amqp://localhost',
bindings,
channelOptions = {
noAck: false
},
exchangeName,
exchangeType = 'topic',
exchangeOptions = {
durable: false
},
onChannelReady
If, for some reason, you want to close the connetion, you can use:
the object connection.close()`