Create a producer for an exchange of the fanout type.
Multiple fanout producers can fanout to multiple fanout consumers.
Init example:
const iamqp = require('iamqp');
const amqpUri = 'amqp://localhost';
const fanoutChannel = 'fanout-channel-a';
let fanoutProducer = new iamqp.FanoutProducer(amqpUri, fanoutChannel);
// This needs to be done or the errors will bubble up.
fanoutProducer.getEventer().on('error', (err) => {
console.log('fanout producer error:' + err.message);
});
// For when the connection is established.
fanoutProducer.getEventer().on('connected', () => {
console.log('fanout producer connected');
});
// Open the connection - this takes some time and is not sync
fanoutProducer.openConnection();
// ...
// Fanout a single message.
let isFanout = fanoutProducer.fanout({
'a': 3
});
// ...
// Close the connection
if (fanoutProducer.closeConnection()) {
console.log('fanout producer connection closing ...');
}
...