matching routing key in callback

21 views
Skip to first unread message

DOBRO

unread,
Jun 2, 2010, 5:06:43 AM6/2/10
to amqp-js
Hi Dan,

I have noticed that matching routing key in function Queue.receive is
not needed.
Lets have a look at lines 148-151 in mq.js

http://github.com/dansimpson/amqp-js/blob/master/javascripts/mq.js

AMQP broker decides to pass the message to queue itself.

When we check if routing key matches another one (in the message
received) then we may miss that message... especially in case of
fanout exchange.

So, function Queue.receive was rewritten like this:

receive: function(msg) {

var ex = this.bindings[msg.exchange];
if(ex) {
for(var k in ex) {
ex[k].fireEvent("rcv", msg);
}
}

},


Now it works properly. Thanks!

dan.simpson

unread,
Jun 2, 2010, 1:00:52 PM6/2/10
to amqp-js
I can see why you were having issues with fanout exchanges.

However, if you have multiple bindings for the same exchange but with
different keys, your solution will produce duplicate results.

For instance:

MQ.queue("auto").bind("myExchange", { key: "key1" } ...);
MQ.queue("auto").bind("myExchange", { key: "key2" } ...);

Now if a message is published on myExchange with routing key key1,
both of the above bindings handlers will be called, which is not
desired behavior.

So I think there is a meet in the middle scenario, where I can check
to see if the binding is a topic exchange, and if it is, then I will
ensure a match, otherwise I will just fire the event for that binding.

Thanks,
Dan

DOBRO

unread,
Jun 2, 2010, 3:10:05 PM6/2/10
to amqp-js
Hmm... you are quite right :)

BTW, I've run into another issue regarding routing key pattern.

Line 96 in mq.js causes the error:

---------------------------------------------------------------------------------------------------------------------------------------------------
TypeError: key.replace is not a function

this.pattern = new RegExp("^" + key.replace('.','\.').replace('*','[^
\.|$]+').replace('#','([^\.|$]+\.)+') + "$");
---------------------------------------------------------------------------------------------------------------------------------------------------

I removed this line... I am up and running :)

DOBRO.
Reply all
Reply to author
Forward
0 new messages