dashersw/cote

One Publisher -> Many Subscribers

bakead17 opened this issue · 7 comments

Is it possible to have multiple subscribers all receive the same message from a publisher?

Yes, that's exactly how it works.

I currently have a message being published based upon device coordinates. When those coordinates change, a single message is sent. That message has multiple subscribers with the same key value in this case "geoUpdate".
For testing purposes when those subscribers receive the message they log "geo1" or "geo2".
The behavior i'm seeing is that only the first subscriber receives the message. So we end up with two nearly identical subscribers, but only the second one receives the message. Any ideas?

var sub = new cote.Subscriber({ name: queueName, key: JSON.stringify(bindArgs) }); sub.on('message', (msg) => { func(msg,func_args); });

are you sure JSON.stringify(bindArgs) gives the same result for both subscribers? if you can share a more complete example, I can take a look at what's wrong.

Here is an output of each (the two relevant) subscriber objects. Does this help?
I can write a quick sample project that I can share to recreate the issue.

image

Sorry for the delay --- here is a full example of what i'm seeing. My feeling is i'm doing something wrong, but i would appreciate any help! =)


`const cote = require('cote');

var buildListener = function(queueName,bindArgs,func){
var sub = new cote.Subscriber({
name: queueName,
key: JSON.stringify(bindArgs)
});
sub.on('message', (msg) => {
func(msg);
});
}

var publish = function(){
let pub = new cote.Publisher({ name: 'message', key: JSON.stringify({'test':'test','woo':'woo'})});
pub.publish('message','testing');
}

var t1 = function(){buildListener('test1',{'test':'test','woo':'woo'},function(){console.log('test1')});};
var t2 = function(){buildListener('test2',{'test':'test','woo':'woo'},function(){console.log('test2')});};
publish(t1(),t2());

`

Good afternoon! Just wondering if I can provide any more information?

Apparently the publisher was creating and sending the message faster than all the listeners could attach.