Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

One Publisher -> Many Subscribers #213

Closed
bakead17 opened this issue Feb 18, 2020 · 7 comments
Closed

One Publisher -> Many Subscribers #213

bakead17 opened this issue Feb 18, 2020 · 7 comments
Labels

Comments

@bakead17
Copy link

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

@dashersw
Copy link
Owner

Yes, that's exactly how it works.

@bakead17
Copy link
Author

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); });

@dashersw
Copy link
Owner

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.

@bakead17
Copy link
Author

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

@bakead17
Copy link
Author

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());

`

@bakead17
Copy link
Author

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

@bakead17
Copy link
Author

bakead17 commented Mar 4, 2020

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants