initialize() { return amqp .connect('amqp://localhost') .then(conn => conn.createChannel()) .then(channel => { this.channel = channel; return this.channel.assertQueue(this.qName); }) .then(q => this.queue = q.queue) .catch(err => console.log(err.stack)) ; }
async function init() { const connection = await amqp.connect(config.rabbitmq.url) const e = config.rabbitmq.exchange const channel = await connection.createChannel() await channel.assertExchange(e, 'fanout', { durable: false, autoDelete: true }) const q = await channel.assertQueue('', { exclusive: true }) await channel.bindQueue(q.queue, e, '') channel.consume(q.queue, (msg) => { console.log(msg.content.toString()) channel.ack(msg) }) }
connectTopicChannel() { amqp.connect(conn, (err, conn) => { if (err) { wl(err, false); } else { conn.createChannel((err, ch) => { ch.assertExchange(exchange, 'topic', { durable: true }); ch.assertQueue(queue, { exclusive: false }, (err, q) => { wl(' [*] Waiting for data. To exit press CTRL+C', true); ch.bindQueue(q.queue, exchange, rabbitMQconfig.keyPattern); // receive data and do whatever ch.consume(q.queue, (msg) => { // write message to consol using our writeLog function wl(`${msg.fields.routingKey}: ${msg.content.toString()}`, true); }, { noAck: true }); }); }); } }); }
amqp.connect('amqp://localhost').then(function(conn) { process.once('SIGINT', function() { conn.close(); }); return conn.createChannel().then(function(ch) { return ch.assertExchange('logs', 'fanout', {durable: true}) .then(function() { var queueName = 'history'; return ch.assertQueue(queueName, {exclusive: false}); }) .then(function(qok) { return ch.bindQueue(qok.queue, 'logs', '').then(function() { return qok.queue; }); }) .then(function(queue) { return ch.consume(queue, logMessage, {noAck: false}); }) .then(function() { console.log(' [*] Waiting for logs. To exit press CTRL+C'); }); function logMessage(msg) { console.log(" " + msg.fields.deliveryTag + " [x] " + msg.content.toString()); } }); }).then(null, console.warn);
amqp.connect('amqp://localhost', (error, connection) => { if (error) throw error; connection.createChannel((error, channel) => { if (error) throw error; channel.assertExchange('logs', 'fanout', { durable: false }); channel.assertQueue('', { exclusive: true }, (error, queue) => { if (error) throw error; channel.bindQueue(queue.queue, 'logs', ''); channel.consume(queue.queue, (msg) => { if(msg.content) { console.log(" [x] %s", msg.content.toString()); } }, { noAck: true }) }); }) });
amqp.connect('amqp://localhost').then((conn) => { return conn.createChannel(); }) .then((ch) => { const exchangeName = 'poc_topic'; const routingKey = process.argv[2]; const queueName = process.argv[3] || `service:${routingKey}`; ch.assertExchange(exchangeName, 'topic', { durable: true }); return ch.assertQueue(queueName, { exclusive: false }).then(q => { ch.bindQueue(q.queue, exchangeName, routingKey); console.log(`[Consumer] Ready to consume on ${exchangeName}::${routingKey}`); return ch.consume(q.queue, msg => { console.log(`[${routingKey}] got message: ${msg.content}`); ch.ack(msg) }); }); }) .catch(console.warn);
log_ch.assertExchange(ex, 'fanout', {durable: false}); log_ch.assertQueue('', {exclusive: true}, function(err, q) { log_ch.bindQueue(q.queue, ex, ''); log_ch.consume(q.queue, function(msg) { var Info = JSON.parse(msg.content.toString()); if (Info.Status=='READY'){ self.RabbitChannel = ch; self.RabbitChannel.assertQueue(rabbitPrefix+'calculate_result', {durable: false,exclusive:true}, function(err, q){ self.RabbitChannel.consume(q.queue, function(msg){ var Answer = JSON.parse(msg.content.toString()); self.ModLen(-1);
const subscribe = async (exchangeName, exchangeType) => { const connect = await amqp.connect(config.rabbitMqUrl) const channel = await connect.createChannel() await channel.assertExchange(exchangeName, exchangeType, {durable: false}) const queue = await channel.assertQueue('', {exclusive: true}) channel.bindQueue(queue.queue, exchangeName, '') const consumeEmitter = new EventEmitter() try { channel.consume(queue.queue, message => { if (message !== null) { consumeEmitter.emit('data', message.content.toString()) } else { const error = new Error('NullMessageException') consumeEmitter.emit('error', error) } }, {noAck: true}) } catch (error) { consumeEmitter.emit('error', error) } return consumeEmitter }
amqp.connect('amqp://localhost').then(function(conn) { process.once('SIGINT', function() { conn.close(); }); return conn.createChannel().then(function(ch) { return ch.assertExchange('logs', 'fanout', {durable: true}) .then(function() { var queueName = process.argv.slice(2).join(' '); return ch.assertQueue(queueName, {exclusive: false}); }) .then(function(qok) { return ch.bindQueue(qok.queue, 'logs', '').then(function() { return qok.queue; }); }) .then(function(queue) { return ch.consume(queue, logMessage, {noAck: false}); }) .then(function() { console.log(' [*] Waiting for logs. To exit press CTRL+C'); }); function logMessage(msg) { console.log(" " + msg.fields.deliveryTag + " [x] " + msg.content.toString()); ch.ack(msg); } }); }).then(null, console.warn);
amqp.connect('amqp://localhost', function(err, conn) { conn.createChannel(function(err, ch) { var ex = 'topic_logs'; ch.assertExchange(ex, 'topic', {durable: false}); ch.assertQueue('', {exclusive: true}, function(err, q) { console.log(' [*] Waiting for logs. To exit press CTRL+C'); args.forEach(function(key) { ch.bindQueue(q.queue, ex, key); }); ch.consume(q.queue, function(msg) { console.log(" [x] %s:'%s'", msg.fields.routingKey, msg.content.toString()); }, {noAck: true}); }); }); });
amqp .connect('amqp://localhost') .then(conn => conn.createChannel()) .then(ch => { channel = ch; return channel.assertQueue('jobs_queue'); }) .then(q => { queue = q.queue; consume(); }) .catch(err => console.log(err.stack)) ;
amqp.connect('amqp://localhost').then(function(conn) { process.once('SIGINT', function() { conn.close(); }); return conn.createChannel().then(function(ch) { return ch.assertExchange('logs', 'fanout', {durable: true}) .then(function() { var queueName = process.argv.slice(2).join(' '); return ch.assertQueue(queueName, {exclusive: false}); }) .then(function(qok) { return ch.get(qok.queue, {noAck: false}); }) .then(function(msg) { if (msg) { console.log(" " + msg.fields.deliveryTag + " [x] " + msg.content.toString()); ch.ack(msg); console.log(" Msg: " + msg.fields.deliveryTag + " Ack'd "); } else { console.log("logMessage: " + "No Messages At This Time."); } }) .then(function() { console.log(' [C] Closing Connection'); }); }); }).then(null, console.warn);
amqp .connect('amqp://localhost') .then(conn => conn.createChannel()) .then(ch => { channel = ch; return channel.assertQueue('results_queue'); }) .then(q => { queue = q.queue; channel.consume(queue, msg => { console.log('Message from worker: ', msg.content.toString()); }); }) .catch(err => console.log(err.stack)) ;
initialize() { return amqp .connect('amqp://localhost') .then(conn => conn.createChannel()) .then(channel => { this.channel = channel; return channel.assertQueue('', {exclusive: true}); }) .then(q => { this.replyQueue = q.queue; return this._listenForResponses(); }) .catch(function(err) { console.log(err); }) ; }