Skip to content

Instantly share code, notes, and snippets.

@Noxalus
Created August 10, 2017 15:06
Show Gist options
  • Save Noxalus/37f8ea30e35f27cfd2cb92a989fc5d1f to your computer and use it in GitHub Desktop.
Save Noxalus/37f8ea30e35f27cfd2cb92a989fc5d1f to your computer and use it in GitHub Desktop.
RabbitMQ DLX + priority queue
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