Created
August 10, 2017 15:06
-
-
Save Noxalus/37f8ea30e35f27cfd2cb92a989fc5d1f to your computer and use it in GitHub Desktop.
RabbitMQ DLX + priority queue
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
let messageOptions = { | |
persistent: true, | |
expiration: 5000, | |
priority: 10 | |
}; | |
var queues = { | |
INCOMING_MESSAGE_QUEUE: { name: 'incomming_message', options: { durable: true }, exchange: 'incomming-message-exchange', routing: 'incomming-message-routing' }, | |
INCOMING_MESSAGE_DLX_QUEUE: { | |
name: 'incomming_message_dlx', | |
options: { | |
durable: true, | |
deadLetterExchange: 'incomming-message-exchange', | |
deadLetterRoutingKey: 'incomming-message-routing', | |
arguments: { | |
'x-max-priority': 10 | |
} | |
} | |
} | |
} | |
pushTask: function({ task, queue, callback, messageOptions }) | |
{ | |
amqp.connect(this.endpoint()).then(connection => | |
{ | |
connection.createChannel().then(channel => | |
{ | |
channel.assertQueue(queue.name, queue.options); | |
if (queue.exchange && queue.routing) | |
{ | |
channel.assertExchange(queue.exchange, 'direct'); | |
channel.bindQueue(queue.name, queue.exchange, queue.routing); | |
} | |
if (!messageOptions) | |
messageOptions = { persistent: true }; | |
channel.sendToQueue(queue.name, new Buffer(JSON.stringify(task)), messageOptions); | |
callback(null); | |
}); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment