Reject Subscriber

332 views
Skip to first unread message

Emerson Macedo

unread,
Oct 21, 2010, 8:45:44 AM10/21/10
to Faye users
Hi,

Does anybody knows how can I reject a subscriber in certain
conditions?

Say I want no more than 100 subscribers in a channel. How can I reject
the others, ensuring they cannot subscribe until the subscribers size
decreases?

Cheers,

Emerson Macedo


James Coglan

unread,
Oct 21, 2010, 9:08:24 AM10/21/10
to faye-...@googlegroups.com
On 21 October 2010 13:45, Emerson Macedo <emer...@gmail.com> wrote:
Does anybody knows how can I reject a subscriber in certain
conditions?

Use an extension, for example:

    server.addExtension({
      incoming: function(message, callback) {
        if (message.channel === '/meta/subscribe' && message.subscription === '/channel/to/limit')
          message.error = 'Cannot subscribe';
        callback(message);
      }
    });

Adding the error makes the core engine ignore the subscription request.

Say I want no more than 100 subscribers in a channel. How can I reject
the others, ensuring they cannot subscribe until the subscribers size
decreases?

This is currently not possible, at least not without peering into the guts a little too much. You can't just monitor requests to /meta/unsubscribe, since subscribers can also be removed automatically if a client is detected as disconnected for too long.

Might be a good idea for me to add an API for inspecting the internal stats of the pubsub engine if this kind of thing is required. Would also make monitoring the Faye server easier.

--
James Coglan
http://jcoglan.com
+44 (0) 7771512510

James Coglan

unread,
Oct 21, 2010, 9:12:54 AM10/21/10
to faye-...@googlegroups.com
On 21 October 2010 14:08, James Coglan <jco...@gmail.com> wrote:
Might be a good idea for me to add an API for inspecting the internal stats of the pubsub engine if this kind of thing is required. Would also make monitoring the Faye server easier.

I've actually added these to my todo list on http://github.com/jcoglan/faye. It will probably help if I refactor the pubsub engine out of the Server class first, which I'm intending to do to make testing easier and so we can support alternate engines (e.g. an engine based on Redis has been proposed).

Emerson Macedo

unread,
Oct 21, 2010, 9:48:54 PM10/21/10
to faye-...@googlegroups.com
How about send an event when a client disconnects? It can be implemented using EventEmiters, what do you think?

Cheers,

Emerson
--
Emerson Macedo
http://codificando.com
@emerleite

James Coglan

unread,
Oct 22, 2010, 5:34:40 AM10/22/10
to Faye users
On Oct 22, 2:48 am, Emerson Macedo <emerle...@gmail.com> wrote:
> How about send an event when a client disconnects? It can be implemented
> using EventEmiters, what do you think?

This keeps coming up and honestly I don't think it's that useful. In
my apps I find that a single Faye client does not often correspond to
an actor in the application, for example a user may use several
clients across page views but should be considered one entity by the
application. The connect/disconnect messages sent by these clients
would not contain information that would let you tie them to the user,
making them not much use for figuring out whether the user is still
active.

I'm not sure I've explained that too well, but the short version is
that I usually need to figure out a ping+timeout setup that makes
sense in each application. You can use Faye channels to send these
pings, but the clients themselves should not get too coupled to your
domain logic.

Emerson Macedo

unread,
Oct 22, 2010, 8:48:29 AM10/22/10
to faye-...@googlegroups.com
I think its clear. My issue is to handle max connections per channel and I didn't realize yet how can I do it. If you have any ideas ...
Reply all
Reply to author
Forward
0 new messages