From 0b634adcdb3fe8aeaa583d371c0065843843fc0c Mon Sep 17 00:00:00 2001 From: tbouchnafa Date: Mon, 6 Aug 2018 17:15:51 +0200 Subject: [PATCH] Allow routing key in header binding --- lib/queue.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/queue.js b/lib/queue.js index 882d4470..fbefb128 100644 --- a/lib/queue.js +++ b/lib/queue.js @@ -307,21 +307,24 @@ Queue.prototype.unbind = function (exchange, routingKey) { }); }; -Queue.prototype.bind_headers = function (/* [exchange,] matchingPairs */) { +Queue.prototype.bind_headers = function (/* [exchange,] matchingPairs [, routingKey] */) { var self = this; // The first argument, exchange is optional. // If not supplied the connection will use the default 'amq.headers' // exchange. + // The third argument, routingKey is optional. If not supplied routingKey is an empty string - var exchange, matchingPairs; + var exchange, routingKey, matchingPairs; - if (arguments.length == 2) { + if (arguments.length >= 2) { exchange = arguments[0]; matchingPairs = arguments[1]; + routingKey = arguments[2] || ''; } else { exchange = 'amq.headers'; matchingPairs = arguments[0]; + routingKey = arguments[1] || ''; } @@ -331,7 +334,7 @@ Queue.prototype.bind_headers = function (/* [exchange,] matchingPairs */) { { reserved1: 0 , queue: self.name , exchange: exchangeName - , routingKey: '' + , routingKey: routingKey , noWait: false , "arguments": matchingPairs });