Created
August 11, 2016 10:43
-
-
Save konstantinzolotarev/4985615a7581c42c700c15694e0f1580 to your computer and use it in GitHub Desktop.
Delayed job with RabbitMQ and amqplib
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict' | |
const amq = require('amqplib') | |
const open = amq.connect('amqp://localhost') | |
const q = 'tasks' | |
open | |
.then(function(conn) { | |
return conn.createChannel(); | |
}) | |
.then(function(ch) { | |
ch.assertExchange('tmp_exchange', 'fanout', { durable: false }) | |
return ch.assertQueue('tmp_queue', { | |
deadLetterExchange: 'final_exchange', | |
messageTtl: 5000 | |
}) | |
.then(function(q) { | |
ch.bindQueue(q.queue, 'tmp_exchange', '') | |
console.log('sending message') | |
return ch.sendToQueue(q.queue, new Buffer('something to do')); | |
}); | |
}) | |
.catch(console.warn); | |
// open | |
// .then(function(conn) { | |
// return conn.createChannel(); | |
// }) | |
// .then(function(ch) { | |
// return ch.assertQueue(q).then(function(ok) { | |
// return ch.consume(q, function(msg) { | |
// if (msg !== null) { | |
// console.log(msg.content.toString()); | |
// ch.ack(msg); | |
// } | |
// }); | |
// }); | |
// }).catch(console.warn); | |
open | |
.then((conn) => conn.createChannel()) | |
.then((ch) => { | |
ch.assertExchange('final_exchange', 'fanout', { durable: false }) | |
return ch.assertQueue('final_queue') | |
.then((q) => { | |
ch.bindQueue(q.queue, 'final_exchange', '') | |
ch.consume(q.queue, (msg) => { | |
console.log('==============================') | |
console.log(msg.content.toString()) | |
console.log('==============================') | |
ch.ack(msg) | |
}) | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment