Reputation: 271
I am trying to broadcast a message through the Node.js
service socket.io
(http://socket.io/) to certain subset of all subscribers.
To be more exact, I would like to use channels that users can subscribe to, in order to efficiently push messages to a couple hundred people at the same time.
I'm not really sure ifaddEvent('channel_name',x)
is the way to go.
I have not found anything in the docs. Any ideas?
Thanks Mat
Upvotes: 5
Views: 8421
Reputation: 1506
Seems like this other question would also answer this one, but if it doesnt you should look at socket.io namespaces, think it was introduced just recently but thought it was worth mentioning
Upvotes: 0
Reputation: 2108
This is a little late(!) but I spotted it in my referrer logs (I'm the author of Faye). It's easy to publish messages from your application whether it's in the same server as Faye or not. For example:
var faye = require('faye'),
http = require('http');
// Set up the server
var server = http.createServer(function(req, res) {
// dispatch to your app logic...
});
var bayeux = new faye.NodeAdapter({mount: '/bayeux'});
bayeux.attach(server);
server.listen(8000);
If your app logic is in the same server process you can do this:
bayeux.getClient().publish('/channel', {hello: 'world'});
Otherwise you can make a client in Node that connects to your Faye server:
var client = new faye.Client('http://0.0.0.0:8000/bayeux');
client.publish('/channel', {hello: 'world'});
Either way, the Faye server will relay the message to any subscribed clients whether they are server- or client-side. Hope that helps.
Upvotes: 4
Reputation: 1838
I'm starting my research into the same problem at the moment. Socket.io looks great, but yes, i think you have to manage the subscriber list yourself. Most example apps out there only use a single subscriber list.
I did come across this... http://faye.jcoglan.com/
It turns your server into a pubsub app. It looks like it manages subscriber lists quite well and it provides a nice hierarchy for channels. However, I can't find an example of it responding to published events within the same app that is running faye?? I'm guessing it's possible. I'll have to have a look at the source. It does seem to give an example of running a separate node app on the server that functions as a client.
The other feature I'm looking for is permissions. I'd want only certain clients to be able to publish to certain channels.
Upvotes: 0
Reputation: 8481
It seems you can use Redis publish/subscribe functionality for this. See this link.
Upvotes: 0